Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BitmapFactory.decodeStream(...) called twice #1

Closed
TannerS opened this issue Jan 17, 2016 · 1 comment
Closed

BitmapFactory.decodeStream(...) called twice #1

TannerS opened this issue Jan 17, 2016 · 1 comment

Comments

@TannerS
Copy link

TannerS commented Jan 17, 2016

Was it intentionally, to have

BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, opts);

called twice within the private Bitmap loadBitmapFromUri(Uri uri) method

it is used to return a Bitmap which is why it is returned such as

return BitmapFactory.decodeStream(getContentResolver().openInputStream(uri), null, opts);

but it is also called in the method without returning or assigning it to anything, was this a typo or intentionally?

@keithito
Copy link
Contributor

Hi Tanner,

This is intentional. The first call passes an Options object with inJustDecodeBounds set to true. This causes the BitmapFactory to retrieve the dimensions without decoding the bitmap. In the following lines, these dimensions are used to compute a sampleSize to load an image that is approximately the same size as the screen. Then the second call to decodeStream decodes a bitmap with this size.

For more info, please see the Android docs here:
http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants