Question

I've made the following code to get a bitmap size.

// Decode the Uri to get the bitmap
BitmapFactory.Options optionsSize = new BitmapFactory.Options();
optionsSize.inJustDecodeBounds = true;
Bitmap originalBimap = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(uri), null, optionsSize);

// Get original size
int width = optionsSize.outWidth;
int height = optionsSize.outHeight;

What is strange, is the varaibles height and width have the correct values but originalBimap is null.

The Uri targets a picture in gallery (content://media/...).

Did I make something wrong ?

Was it helpful?

Solution

Yes. When you set inJustDecodeBounds to true, then it does not return the bitmap. It only queries to set the "out" fields of BitmapFactory.Options.

inJustDecodeBounds

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top