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.
Calling the decodeStream method from your java application will invoke a call to the native decoding implementation based on the InputStream type. See public static Bitmap decodeStream(InputStream is, Rect outPadding, Options opts)
here.
The options are passed on to the native decoder implementation with signature static jobject doDecode(JNIEnv* env, SkStreamRewindable* stream, jobject padding, jobject options)
for decoding, see here.
Inspecting the code further, you will see that when the option inJustDecodeBounds=true
, the boolean onlyDecodeSize
is set to true in the doDecode method. The decode method will then process the stream up until all size meta data has been extract. At this point it will return a null pointer, giving you access to the image meta data but not the full image.