2014-09-23 186 views
1

我的代码:为什么BitmapFactory.decodeFile返回null?

BitmapFactory.Options opt = new BitmapFactory.Options(); 
opt.inJustDecodeBounds = true; 
Bitmap rotateBmp = BitmapFactory.decodeFile("/storage/sdcard0/FastBurstCamera/2014-09-15 05-24-07-461.jpg", opt); 

文件/存储/ sdcard0/FastBurstCamera/2014年9月15日05-24-07-461.jpg存在,但rotateBmp是空的,为什么?

回答

3

存在file/storage/sdcard0/FastBurstCamera/2014-09-15 05-24-07-461.jpg,但rotateBmp为空,为什么?

因为这就是你要求的。

引述the documentation for decodeFile()(强调):

解码的位图,或者null如果图像数据不能被解码,或者,如果OPTS是非空,如果OPTS要求仅返回的大小(在opts.outWidth和opts.outHeight)

引用the documentation for inJustDecodeBounds

如果设置为true,解码器将返回null(无位图),但out ...字段仍将被设置,允许调用者查询位图而不必为其像素分配内存。

+0

感谢您的好意,根据您的建议,我删除了“opt.inJustDecodeBounds = true;”,然后它就可以工作。再次感谢你! – 2014-09-23 11:57:46

2
  • 原因可能是图像尺寸大。检查this question
  • 另一个原因可能是不会将READ_EXTERNAL_STORAGE和/或WRITE_EXTERNAL_STORAGE权限添加到您的清单文件。你添加了吗?