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

问题描述

我使用C#和想用JPEG格式保存图像。但是.NET降低了图像的质量,并将其保存以com pression这是不够的。

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.

我要保存的文件与原来的质量和大小。我现在用的是下面的code,但COM pression和质量并不像原来的。

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

我归档工作室照片和质量和玉米pression是非常重要的。谢谢你。

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

推荐答案

它看起来像你将质量设置为100%。这意味着将不会有玉米pression

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

如果您更改COM pression水平(80,50,等),你的质量unsatisifed,你可能会想尝试不同的图像库。 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时,意味着无损COM pression。加载图像,做一些给它,然后再保存它最终会导致图像质量下降。如果需要修改和保存图像,而不会失去任何你需要使用无损格式,如TIFF,PNG或BMP数据。我与COM pressed TIFF去(因为它仍然无损,即使它的COM pressed)或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 COM pression用C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 16:21