1

I'm experimenting with image re-sizing in asp.net. Actual re-sizing code aside, I am wondering why there is such a big difference between bitmap's Save overloads

method 1

   ImageCodecInfo jpgEncoder =
        ImageCodecInfo.GetImageDecoders()
        .First(c => c.FormatID == ImageFormat.Jpeg.Guid);
    Encoder encoder = Encoder.Quality;
    EncoderParameters encoderParameters = new EncoderParameters(1);
    encoderParameters.Param[0] = new EncoderParameter(encoder, (long)quality);
bitmap.Save(_current_context.Response.OutputStream,jpgEncoder,encoderParameters)

method 2

bitmap.Save(_current_context.Response.OutputStream,ImageFormat.Jpeg)

So Method 1, at 100 quality, outputs this particular jpeg image at about 250kb. At 90 quality, it drops to about 100kb

Method 2 however, drops the image to about 60kb, which is a huge difference and with no visible difference as well.

I can't seem to find anywhere why the difference is so big, MSDN has zero details on these two overloads.

Any insight is appreciated. Thanks

1 Answer 1

0

Looking at the ImageCodeInfo / Encoder objects which don't seem to provide a way to extract the settings out. I would assume that by default it's setting the Quality to 100 on the save.

Without looking more into the Windows Imaging stuff it's really hard to say.

You could try doing your code with the Default save (Method2) , and the Method 1 with 100 and see if they are the same. it's most likely that way.

http://msdn.microsoft.com/en-us/library/system.drawing.imaging.encoder.quality.aspx#Y800

2
  • unfortunately not, method 1 at 100 quality and method 2 are drastically different, that's why i was asking
    – andryuha
    Jul 5, 2012 at 16:53
  • i guess my point is to experiment with the different values and see if they marry up. from my observation i couldn't find how to extract the defaults that are in use without deeper investigating Windows Imaging which is what .NET is using for this stuff.
    – Paul Farry
    Jul 10, 2012 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.