c#: reduced image quality when saving JPEG at 100% quality

痴心易碎 提交于 2019-12-06 08:51:49

问题


I'm just loading JPEG image and saving it without any manipulation with it. But image quality noticeably reducing.

Here is the code:

Bitmap imgOutput = new Bitmap(@"D:\image.jpg");
Graphics outputGraphics = Graphics.FromImage(imgOutput);      

EncoderParameters myEncoderParameters = new EncoderParameters(3);
myEncoderParameters.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 100L);
myEncoderParameters.Param[1] = new EncoderParameter(System.Drawing.Imaging.Encoder.ScanMethod, (int)EncoderValue.ScanMethodInterlaced);
myEncoderParameters.Param[2] = new EncoderParameter(System.Drawing.Imaging.Encoder.RenderMethod, (int)EncoderValue.RenderProgressive);

ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs)
{
    if (codec.MimeType == "image/jpeg")
        ici = codec;
}

imgOutput.Save(@"D:\result.jpg", ici, myEncoderParameters);

And what I get: http://i.imgur.com/5bG1tPM.jpg zoom: http://i.imgur.com/vdx8sL5.jpg

Is there another image quality settings?


回答1:


JPEG, being a lossy format introduces loss on every save. It is also particularly bad at compressing sharp edges. According to this MSDN article, you're setting the image quality correctly. You can play with the other settings if you want to try and optimize the image quality, as I don't know how you came up with the ScanMethod and RenderMethod. However, the best way in my opinion is to use a lossless format (PNG, TIFF, etc).

Update

It appears that this is due to the bad GDI+ JPEG encoder. More on it on the MSDN forums. The conclusion is - use a third party imaging library, there are plenty free ones out there.



来源:https://stackoverflow.com/questions/16373621/c-reduced-image-quality-when-saving-jpeg-at-100-quality

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!