gpt4 book ai didi

android - 无法解码流

转载 作者:行者123 更新时间:2023-12-01 15:07:13 25 4
gpt4 key购买 nike

我想通过使用图像文件的绝对路径将图像保存到 Bitmap 中,下面是我的代码:

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");

以下是我的输出,包括异常:

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

问题是什么?我确实在 list 中添加了 WRITE_EXTERNAL_STORAGE 权限。

最佳答案

请看下面这里,你需要解码文件路径然后你会得到位图。

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");

关于android - 无法解码流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41216176/

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