无法解码流 [英] Unable to decode stream
本文介绍了无法解码流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想使用图像文件的绝对路径将图像保存到Bitmap中,下面是我的代码:
I want to save an image into Bitmap by using the absolute path of the image file, below is my code:
Log.d("PhotoPath", selected.getImagePath());
File file = new File(selected.getImagePath());
if(file.exists())
{
Log.d("File", "Exist");
Bitmap d = new BitmapDrawable(getResources(), selected.getImagePath()).getBitmap();
int nh = (int) (d.getHeight() * (512.0 / d.getWidth()));
Bitmap scaled = Bitmap.createScaledBitmap(d, 512, nh, true);
iv_Photo.setImageBitmap(scaled);
}
else
Log.d("File", "Not exist");
下面是我的输出,包括以下异常:
Below is my output including the exception:
D/PhotoPath: /storage/emulated/0/DCIM/POEMS/JPEG_20161214_170251_1637243168.jpg
D/File: Exist
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /storage/emulated/0/DCIM/POEMS/JPEG_20161214_170251_1637243168.jpg (Permission denied)
W/BitmapDrawable: BitmapDrawable cannot decode /storage/emulated/0/DCIM/POEMS/JPEG_20161214_170251_1637243168.jpg
出什么问题了?我确实在清单中添加了WRITE_EXTERNAL_STORAGE
权限.
What is the problem? I did add WRITE_EXTERNAL_STORAGE
permission in Manifest.
推荐答案
请在此处查看下面的内容,您需要解码文件路径,然后才能获得位图.
Please see below here, you need to decode file path then you will get bitmap.
Log.d("PhotoPath", selected.getImagePath());
File file = new File(selected.getImagePath());
if(file.exists())
{
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
}
else
Log.d("File", "Not exist");
这篇关于无法解码流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文