I’m resizing jpeg 1200×900 ,556kb by method:
public static Image ResizeImage(Image imgToResize, int height) //height=400
{
int destWidth;
int destHeight;
int sourceWidth = imgToResize.Width;
int sourceHeight = imgToResize.Height;
float nPercent = 0;
float nPercentH = 0;
nPercentH = ((float)height / (float)sourceHeight);
nPercent = nPercentH;
destWidth = (int)(sourceWidth * nPercent);
destHeight = height;
Bitmap b = new Bitmap(destWidth, destHeight);
Graphics g = Graphics.FromImage((Image)b);
g.InterpolationMode = InterpolationMode.HighQualityBicubic;
g.DrawImage(imgToResize, 0, 0, destWidth, destHeight);
g.Dispose();
return b;
}
SavingŁ
Image image = Image.FromStream(new FileStream(path, FileMode.Open));
Image imageAfterResizing =ResizeImage(image,400);
imageAfterResizing.Save(@"c:\myPhoto.jpg");
gives me 555kb 533×400 jpeg.
Why this photo is so heavy.
For photo jpeg 2111kb 2156×1571
I get 556kb 533×400 jpeg
Why in first case is so terrible !
http://img6.imageshack.us/img6/1127/photo1nz.jpg
http://img248.imageshack.us/img248/8063/photo2y.jpg
Looks like you aren’t specifying the save format, it’s likely coming out the other end as a bitmap.
Specify the format during the save: img.Save(“C:\\foo.jpg”, ImageFormat.Jpeg);