.NET保存的JPEG具有相同的质量,因为它被加载 [英] .NET Saving jpeg with the same quality as it was loaded

查看:118
本文介绍了.NET保存的JPEG具有相同的质量,因为它被加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一门大炮数码相机,我把它拍照与超细质量和它输出.jpg文件的大小300万。
如果我加载像这样在ASP.NET(这是非常有用的改变它的dpi分辨率或裁剪或whaterver)

I have a cannon digital camera and I set it to take pictures with superfine quality and it outputs a .jpg file 3 mega in size. If I load it like this in ASP.NET(this is useful to change it's dpi resolution or crop it or whaterver)

imgPicture = Image.FromFile(Config.WorkDirectory + this.TempPhotoName);
bmpPicture = new Bitmap(imgPicture);

然后我再保存它是这样的:

and then I save it again like this:

bmpModified.Save(Config.WorkDirectory + this.TempPhotoName,System.Drawing.Imaging.ImageFormat.Jpeg);

它输出JPG格式,这只是700KB左右的规模。有质量的损失。

it outputs a jpg that is only 700KB or so in size. There is a loss of quality.

我也试过保存这样的:

bmpPicture.Save(Config.WorkDirectory + this.TempPhotoName, codecJpeg, encparams);

其中codecJpeg是

where codecJpeg is

ImageCodecInfo codecJpeg = this.getEncoderInfo("image/jpeg");


    private ImageCodecInfo getEncoderInfo(string mimeType)
    {
        // Get image codecs for all image formats
        ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();

        // Find the correct image codec
        for (int i = 0; i < codecs.Length; i++)
            if (codecs[i].MimeType == mimeType)
                return codecs[i];
        return null;
    }

和encparams:

and encparams:

EncoderParameters encparams = new EncoderParameters(1);
encparams.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, 97L);

这样的大小(我怀疑也是质量)保持,但我输入查询用手质量。

This way the size(and I suspect also the quality) is maintained but I am inputing the quality by hand.

我要问:

有没有办法将图像具有相同的品质保存,因为它是没有硬编码的质量值装?

Is there a way to save the image with the same quality as it was loaded without hardcoding the quality value?

感谢您提前

推荐答案

因此​​,它听起来就像你知道如何设置的质量,你真的只需要知道如何的从原来的取的质量形象?

So it sounds like you know how to set the quality, you really just need to know how to fetch the quality from the original image?

我怀疑 图片.PropertyItems 是你的朋友,如果质量在开始与元数据。 (我不知道是否有甚至在JPEG品质连接codeRS标准等级。)

I suspect that Image.PropertyItems is your friend, if the quality is in the metadata to start with. (I don't know if there's even a standard scale for quality within JPEG encoders.)

编辑:我刚刚查,和JPEG我下载没有任何标签的质量

I've just checked, and a jpeg I downloaded didn't have any tags for quality.

一个选择可能是摸出文件应该有多大最终有大致相同的质量,然后保存了好几次,做一个二进制搜索制定出最合适的品质。过甜的,但它可能只是工作。

One option might be to work out how big the file should end up to have roughly the same quality, and then save it several times, doing a binary search to work out the most appropriate quality. Icky, but it might just work.

我暗自怀疑存在的不是的一个办法只有preserve原来的画质设置,虽然我没有很好的理由,这种怀疑...

I have a sneaking suspicion that there isn't a way to just preserve the original quality setting, although I don't have very good grounds for that suspicion...

这篇关于.NET保存的JPEG具有相同的质量,因为它被加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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