سؤال

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 ?

هل كانت مفيدة؟

المحلول

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top