c#:以100%的质量保存JPEG时,图像质量降低 [英] c#: reduced image quality when saving JPEG at 100% quality

查看:438
本文介绍了c#:以100%的质量保存JPEG时,图像质量降低的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是加载JPEG图像并保存它,而没有对其进行任何操作.但是图像质量明显下降.

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

这是代码:

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);

我得到的是: http://i.imgur.com/5bG1tPM.jpg 缩放: http://i.imgur.com/vdx8sL5.jpg

还有其他图像质量设置吗?

Is there another image quality settings?

推荐答案

JPEG是一种有损格式,每次保存都会造成损失.在压缩尖锐边缘时也特别不利.根据此MSDN文章,您正在正确设置图像质量.如果您想尝试并优化图像质量,则可以使用其他设置,因为我不知道您是如何想到ScanMethod和RenderMethod的.但是,我认为最好的方法是使用无损格式(PNG,TIFF等).

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).

更新

这似乎是由于错误的GDI + JPEG编码器引起的.有关更多信息,请参见 MSDN论坛.结论是-使用第三方影像库,那里有很多免费的库.

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.

这篇关于c#:以100%的质量保存JPEG时,图像质量降低的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆