简体   繁体   English

调整JPEG大小而不会降低质量

[英]Resizing JPEG without losing Quality

I am trying to work on a small webbased Image editor with .NET . 我正在尝试使用.NET开发基于Web的小型图像编辑器。 I am having issue with JPEG image resize.As I understand there is no way to manipulate JPEG without loosing some quality and saw this as only way to do it . 我在调整JPEG图像大小时遇到​​问题。据我所知,在不降低质量的情况下无法操作JPEG,这是唯一的方法。 Resizing an image in asp.net without losing the image quality . 在asp.net中调整图像大小而不损失图像质量 In this sample target image is saved as a png . 在此样本中,目标图像另存为png。

So What I want to do is 所以我想做的是
1. When user uploads image save it as PNG 1.用户上传图片时将其另存为PNG
2. Manipulate it like resize rotate etc 2.调整大小,如旋转大小等
3. Save it as JPEG 3.将其另存为JPEG

If I save that png as a jpeg will that loose quality as well ? 如果我将png保存为jpeg,那么质量也会宽松吗? Or should it be fine as its just saving it with other format and not really manipulating it. 还是应该很好,因为它只是将其保存为其他格式,而不是真正地对其进行操作。

Thanks. 谢谢。

If you don't want to lose quality, don't use jpeg. 如果您不想失去质量,请不要使用jpeg。 What's wrong with just keeping it png? 仅保留png有什么问题? When you resave the png as jpeg, yes you will lose some quality depending on the compression ratio you choose. 当您将png重新保存为jpeg时,是的,根据您选择的压缩率,您将失去一些质量。 That's the nature of the jpeg format. 这就是jpeg格式的本质。

PNG format is a lossless format, so as long as you are creating the PNG with the source image you are OK. PNG格式是一种无损格式,因此,只要您使用源图像创建PNG,就可以了。

For reference: 以供参考:

JPEG - Lossy for most of the specifications (the new spec has a lossless format also, but not many libraries support it yet). JPEG-对于大多数规范,都是有损的(新规范也具有无损格式,但是还没有很多库支持它)。

PNG - Lossless PNG-无损

TIFF - Lossless (RLE encoding) TIFF-无损(RLE编码)

BMP - Lossless (RAW encoding) BMP-无损(RAW编码)

Yes, it will lose quality as well. 是的,它也会失去质量。 The difficulty of resizing JPEG is due to the compression (aka encoding) algorithm itself, so it is irrelevant what image format is the source, because to encode the image you have to decode it to a raw format (bitmap, that is) first. 调整JPEG大小的困难是由于压缩(aka编码)算法本身造成的,因此与原始图像格式无关,因为要对图像进行编码,必须首先将其解码为原始格式(即位图)。

Also, it's good to remember, that if the image you're encoding has been a JPEG before, encoder will have harder time encoding it again after resizing. 另外,请记住,如果您要编码的图像以前是JPEG,则在调整大小后,编码器将很难再对其进行编码。 JPEG divides image into 8x8 pixel blocks to perform the encoding, and resizing moves the borders of these blocks. JPEG将图像划分为8x8像素块以执行编码,并调整大小以移动这些块的边界。 This is important note, because with higher compression ratios the borders between blocks become sharper -- and JPEG is especially bad in encoding irregular sharp edges in image (I'm skipping all the internal details, they're not important for now, comment if you'd like to know them anyway). 这一点很重要,因为随着更高的压缩比,块之间的边界会变得更加清晰-JPEG在编码图像中不规则的锐利边缘方面尤其不利(我跳过了所有内部细节,目前它们并不重要,请评论您仍然想了解他们)。 This effect is not important for typical photo compression ratios, though. 但是,对于典型的照片压缩率,此效果并不重要。

Essentially: if you encode image as JPEG, you have to encode it at least once (obvious, isn't it? ;) ). 本质上:如果将图像编码为JPEG,则必须至少编码一次(很明显,不是吗?;))。 And JPEG (ie lossy) encoding equals losing quality. JPEG(即有损)编码等于丢失质量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM