开发者

Resizing gives me to heavy image

I'm resizing jpeg 1200x900 ,556kb by method:

public static Image ResizeImage(Image imgToResize, int height) //height=400
{
    int destWidth;
    int destHeight;

    int sou开发者_JAVA技巧rceWidth = 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 533x400 jpeg.

Why this photo is so heavy.

For photo jpeg 2111kb 2156x1571 I get 556kb 533x400 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);


The compression of the JPEG image is decided when you save it, which is not included in the code that you show.

The default level of compression is pretty low, so you can set it to compress the image a bit more when you save it.


I think you'll find that in both cases you've converted larger jpegs into bitmap images.

Both bitmaps are 533x400 pixels and both have roughly the same file size 556kb.

If you want to resize the file size, you'll need to use a different format than a bitmap image.


  • Are you sure it is an JPEG, not some other file format with a JPEG file extension?
  • Set the JPEG quality lower.
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜