0

When we pass Options with inJustDecodeBounds=true to the BitmapFactory.decodeStream method, it decodes only the file size(Height and width).
How does android calculate the size (height and width)?
Does it download the full file and then calculates the size?
In InputStream there a method avaliable(), but it returns only the estimated size.
I want to know the internal working of this.

4

1 回答 1

0

从您的 Java 应用程序调用 decodeStream 方法将调用基于 InputStream 类型的本机解码实现。见public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts) 这里

这些选项被传递给带有解码签名的本机解码器实现static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding, jobject options)请参见此处。

进一步检查代码,您会看到当 option 时inJustDecodeBounds=true,布尔值onlyDecodeSize在 doDecode 方法中设置为 true。然后,解码方法将处理流直到提取所有大小的元数据。此时它将返回一个空指针,让您可以访问图像元数据,但不能访问完整图像。

于 2017-12-25T10:23:27.990 回答