解码时,BitmapFactory.decodeFile()文件是否解压缩JPEG图像? [英] Does BitmapFactory.decodeFile() file decompress the JPEG image when decoding it?

查看:345
本文介绍了解码时,BitmapFactory.decodeFile()文件是否解压缩JPEG图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JPEG是一种压缩格式. 在将JPEG图像解码为内存中的Bitmap时,BitmapFactory.decodeFile("JPEG文件的路径")是否解压缩JPEG图像? 当我在解码后的JPEG文件的结果位图上使用Bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream)时,则压缩图像的大小大于原始图像的大小.有人能确切解释这种现象吗?

JPEG is a compressed format. Does BitmapFactory.decodeFile("path to a JPEG file") decompress the JPEG image when decoding it as a Bitmap in the memory? And when I use Bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream) on the resulting bitmap from the decoded JPEG file, then the size of the compressed image is more than the size of the original image. Can anybody exactly explain this phenomenon?

推荐答案

当将BitmapFactory.decodeFile("JPEG文件的路径")解码为内存中的位图时,是否解压缩JPEG图像?

Does BitmapFactory.decodeFile("path to a JPEG file") decompress the JPEG image when decoding it as a Bitmap in the memory?

是的

当我在解码的JPEG文件的结果位图上使用Bitmap.compress(Bitmap.CompressFormat.JPEG,100,byteArrayOutputStream)时,则压缩图像的大小大于原始图像的大小

And when I use Bitmap.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream) on the resulting bitmap from the decoded JPEG file, then the size of the compressed image is more than the size of the original image

那是很有可能的.质量等级为100,尽管可能无法保证,但我认为这很可能.

That is very possible. With a quality level of 100, I would consider it likely, though perhaps not assured.

有人能确切解释这种现象吗?

Can anybody exactly explain this phenomenon?

不要求它们与JPEG相同.实际上,如果 相同,几乎是随机的机会.

There is no requirement that they be the same for a JPEG. In fact, it will be almost random chance if they are the same.

假设我们从内存图像开始(B 原始,其中B是位图的缩写).然后,我们将该图像压缩为JPEG(J 原始). JPEG结合了有损压缩算法,可通过考虑人眼无法识别少量变化这一事实来对现实图像(例如照片)实现更好的压缩.

Suppose we start with an in-memory image (Boriginal, where B is short for bitmap). We then compress that image to a JPEG (Joriginal). JPEG incorporates a lossy compression algorithm, to achieve better compression on real-world images (e.g., photos) by taking into account the fact that human eyes cannot discern small amounts of change.

假设我们然后将J 原始解码回内存中的位图(B reloaded ). B 重新加载 将与B 原始不是同一张图片,因为JPEG压缩将更改该图片. B reloaded 与B 原始的接近程度取决于多种因素,部分取决于图像本身,部分取决于保存JPEG时使用的质量等级(代码中的100).此质量级别的范围是0到100,其中100表示​​最高质量.

Suppose we then decode Joriginal back into an in-memory bitmap (Breloaded). Breloaded will not be the same image as Boriginal, because the JPEG compression will have changed the image. How close Breloaded is to Boriginal will depend on a variety of factors, partly tied to the image itself, and partly tied to the quality level used when saving the JPEG (the 100 in your code). This quality level ranges from 0 to 100, with 100 meaning highest quality.

如果我们随后将B reloaded 压缩为第二个JPEG(J reloaded ),则新的JPEG 将与原始JPEG不同. JPEG(J 原始).部分原因是,根据上一段,源位图已更改.部分原因是因为我们可能没有选择与原始压缩工作相同的质量水平.

If we then compress Breloaded to a second JPEG (Jreloaded), the new JPEG will not be the same as the original JPEG (Joriginal). Partly, that is because the source bitmap changed, per the previous paragraph. Partly, that is because we might not choose the same quality level as we did with the original compression work.

在您的情况下,您没有创建J 原始.您不一定知道使用什么质量级别(该信息可能存储在JPEG标头中;我忘记了).但是由于B reloaded 与原始位图(无论它来自何处)不同,因此当将位图压缩为J reloaded 时,它将与J 原始.总体而言,很难概括地说是较大还是较小.但是,由于您选择的质量等级为100,并且J 原始可能已经以较低的质量等级进行了压缩,因此压缩后的图像很容易变大.

In your case, you did not create Joriginal. You do not necessarily know what quality level was used (that information might be stored in the JPEG header; I forget). But because Breloaded will be different that the original bitmap (wherever it came from), when you compress the bitmap to Jreloaded, it is going to be different than Joriginal. On the whole, whether it is larger or smaller is difficult to say in the abstract. However, since you are choosing a quality level of 100, and Joriginal might well have been compressed with a lower quality level, your compressed image very easily could be larger.

这与Android无关.这纯粹是JPEG工作方式的功能.如果您对JPEG本身还有其他疑问,不妨阅读有关JPEG的更多信息,并在以下网站上提问一些与图片格式有关的网站.

This has nothing to do with Android. This is purely a function of how JPEG works. If you have further questions about JPEG itself, you may wish to read more about JPEG and ask questions on some site that has something to do with image formats.

这篇关于解码时,BitmapFactory.decodeFile()文件是否解压缩JPEG图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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