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

查看:31
本文介绍了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:
esult.jpg", ici, myEncoderParameters);

我得到了什么:http://i.imgur.com/5bG1tPM.jpg缩放:http://i.imgur.com/vdx8sL5.jpg

还有其他画质设置吗?

推荐答案

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天全站免登陆