Android位图解码流返回null

时间:2014-04-15 19:33:03

标签: android android-bitmap

我已经制作了以下代码以获得bitmap尺寸。

// 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;

奇怪的是,变量heightwidth具有正确的值,但originalBimapnull

Uri定位图库中的图片(content://media/...)。

我做错了吗?

1 个答案:

答案 0 :(得分:4)

是。将inJustDecodeBounds设置为true时,它不会返回位图。它只查询设置" out" BitmapFactory.Options

的字段

inJustDecodeBounds

相关问题