作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经尝试了我在 stackoverflow 上找到的所有解决方案来解决这个问题,但都是徒劳的。运行以下代码时,mAlbumPhotoUri 为“/mnt/sdcard/photo/1342147146535.jpg”,Uri 类型。 file.exists() 表示此文件存在,但在执行最后一行代码后 resultBitmap 为空。
我做错了什么?
File file = new File(mAlbumPhotoUri.toString());
if(file.exists()){
Toast.makeText(this, "File exists in /mnt", Toast.LENGTH_LONG);}
else {
Toast.makeText(this, "File NOT exists in /mnt", Toast.LENGTH_LONG);}
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true; //only get the size of the bitmap
if (resultPhotoBitmap != null) {
resultPhotoBitmap.recycle();
}
String fname=new File(mAlbumPhotoUri.toString()).getAbsolutePath();
resultPhotoBitmap = BitmapFactory.decodeFile(fname, options);
最佳答案
将选项 inJustDecodeBounds
添加到您的 BitmapFactory
中就是这样;它只解码 Bitmap
的大小并将该数据加载回选项对象的 outHeight
和 outWidth
。它不会解码实际的 Bitmap
并将其返回给您。
如果你想真正获得Bitmap
本身,删除那个选项并再次调用decodeFile()
。
关于android - decodeFile 为现有文件返回空位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11473819/
我是一名优秀的程序员,十分优秀!