繁体   English   中英

Android位图解码流返回null

[英]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;

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

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

我做错什么了吗?

是。 inJustDecodeBounds设置为true时,它不会返回位图。 它仅查询设置BitmapFactory.Options的“输出”字段。

inJustDecodeBounds

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM