[英]Android bitmap decode stream returns null
我编写了以下代码来获取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;
奇怪的是,变量height
和width
具有正确的值,但是originalBimap
为null
。
Uri
定位到图库中的图片( content://media/...
)。
我做错什么了吗?
是。 将inJustDecodeBounds
设置为true时,它不会返回位图。 它仅查询设置BitmapFactory.Options
的“输出”字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.