问题
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