问题描述
我正在尝试使用.NET开发基于Web的小型图像编辑器.我在调整JPEG图像大小时遇到问题.据我所知,在不降低质量的情况下无法操纵JPEG,这是实现此目的的唯一方法.在asp.net中调整图像大小而不会丢失图像质量.在此样本中,目标图像另存为png.
I am trying to work on a small webbased Image editor with .NET . 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 . Resizing an image in asp.net without losing the image quality . In this sample target image is saved as a png .
所以我想做的是
1.用户上传图片时将其另存为PNG
2.调整大小,如旋转大小等操作
3.将其另存为JPEG
So What I want to do is
1. When user uploads image save it as PNG
2. Manipulate it like resize rotate etc
3. Save it as JPEG
如果我将png保存为jpeg,那么质量也会松散吗?还是应该很好,因为它只是将其保存为其他格式,而不是真正地对其进行操作.
If I save that png as a jpeg will that loose quality as well ? Or should it be fine as its just saving it with other format and not really manipulating it.
谢谢.
推荐答案
是的,它也会失去质量.调整JPEG大小的困难是由于压缩(aka编码)算法本身引起的,因此与图像格式的来源无关,因为要对图像进行编码,必须首先将其解码为原始格式(即位图).
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,那么在调整大小之后,编码器将很难再对其进行编码.JPEG将图像划分为8x8像素块以执行编码,并调整大小以移动这些块的边界.这一点很重要,因为随着更高的压缩比,块之间的边界会变得更清晰-JPEG在编码图像中不规则的锐利边缘方面尤其不利(我跳过了所有内部细节,目前它们并不重要,请评论您仍然想了解他们).但是,对于典型的照片压缩率来说,这种效果并不重要.
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 divides image into 8x8 pixel blocks to perform the encoding, and resizing moves the borders of these blocks. 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). This effect is not important for typical photo compression ratios, though.
本质上:如果将图像编码为JPEG,则必须至少编码一次(很明显,不是吗?;)).JPEG(即有损)编码等于丢失质量.
这篇关于在不损失质量的情况下调整JPEG大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!