gpt4 book ai didi

android - decodeFile 为现有文件返回空位图

转载 作者:行者123 更新时间:2023-11-29 14:33:15 28 4
gpt4 key购买 nike

我已经尝试了我在 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 的大小并将该数据加载回选项对象的 outHeightoutWidth。它不会解码实际的 Bitmap 并将其返回给您。

如果你想真正获得Bitmap本身,删除那个选项并再次调用decodeFile()

关于android - decodeFile 为现有文件返回空位图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11473819/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com