BitmapFactory.decodeFile();

Car*_*gey 5 android image

在我的应用程序中,我有一个文件:

private File TEMP_PHOTO_FILE = new File(Environment.getExternalStorageDirectory(), "temp_photo.jpg");
Run Code Online (Sandbox Code Playgroud)

这是在我的班级中直接声明的,并且对于那里的所有方法都是可见的.

我想用这个:

Bitmap thePhoto = BitmapFactory.decodeFile(Uri.fromFile(TEMP_PHOTO_FILE).toString());
Run Code Online (Sandbox Code Playgroud)

Uri.fromFile(TEMP_PHOTO_FILE).toString()生成字符串:"file:///mnt/sdcard/temp_photo.jpg"

为什么这不起作用?似乎因为我们正在处理文件,所以应该有一些decodeFile()接受URI作为输入的方法.由于不一致,不允许这样做非常令人沮丧.

Mic*_*Bak 3

“文件://”不起作用。尝试这个:

Bitmap thePhoto = BitmapFactory.decodeFile(TEMP_PHOTO_FILE.getAbsolutePath().toString());
Run Code Online (Sandbox Code Playgroud)