高质量JPEG压缩与c# [英] High quality JPEG compression with c#

查看:961
本文介绍了高质量JPEG压缩与c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#,并想要使用JPEG格式保存图像。但是.NET降低了图像的质量,并用不够的压缩保存它们。

I am using C# and want to save images using JPEG format. However .NET reduces quality of the images and saves them with compression that is not enough.

我想保存文件的原始质量和大小。我使用下面的代码,但压缩和质量不像原来的。

I want to save files with their original quality and size. I am using the following code but compression and quality are not like the original ones.

Bitmap bm = (Bitmap)Image.FromFile(FilePath); 
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders(); 
ImageCodecInfo ici = null; 

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

EncoderParameters ep = new EncoderParameters(); 
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)100); 
bm.Save("C:\\quality" + x.ToString() + ".jpg", ici, ep);

我是档案工作室的照片,质量和压缩非常重要。感谢。

I am archiving studio photos and quality and compression is very important. Thanks.

推荐答案

您似乎将质量设置为100%。这意味着没有压缩。

It looks like you're setting the quality to 100%. That means that there will be no compression.

如果你改变压缩级别(80,50等),你不满意的质量,你可能想尝试不同的图像库。 LEADTools 有一个很好的(非免费)引擎。

If you change the compression level (80, 50, etc.) and you're unsatisifed with the quality, you may want to try a different image library. LEADTools has a good (non-free) engine.

更新:正如评论者所说,100%的质量仍然不意味着使用JPEG时的无损压缩。加载图像,做一些事情,然后再保存它将最终导致图像退化。如果您需要更改和保存图像,而不丢失任何数据,您需要使用无损格式,如TIFF,PNG或BMP。我会用压缩的TIFF(因为它仍然是无损的,即使它是压缩的)或PNG。

UPDATE: As a commenter mentioned, 100% quality still does not mean lossless compression when using JPEG. Loading the image, doing something to it, and then saving it again will ultimately result in image degradation. If you need to alter and save an image without losing any of the data you need to use a lossless format such as TIFF, PNG or BMP. I'd go with compressed TIFF (since it's still lossless even though it's compressed) or PNG.

这篇关于高质量JPEG压缩与c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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