gpt4 book ai didi

android - 使用外部存储文件的路径设置 ImageView 图像

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:39:17 25 4
gpt4 key购买 nike

您好,我想使用保存在 SQLite 数据库中的路径更改 ImageView 的图像。那么我想要实现的是,只要图像可用,它就会显示并保持每秒运行,直到下一个图像可用。但是只要根本没有可显示的内容,就会使用默认图像。但现在我想解决的主要问题是我无法使用我拥有的路径设置 imageView。我尝试了不同的解决方案,例如从路径中制作位图,但仍然收到相同的错误:E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException:/mnt/sdcard/Echo/Images/Awesome4 - 00:01.jpg:打开失败:ENOENT(没有那个文件或目录)

这是我目前的代码:

String path = db.getImagePath(file_name, curTime);

Log.v("Your image filename", file_name);
Log.v("Your currentPosition", curTime);

Log.v("Your Path Playback edit", path);

try{
preview.setImageURI(Uri.parse(Environment.getExternalStorageDirectory()+"/Echo/Images/"+file_name));
}catch (Exception e){
e.printStackTrace();
preview.setImageResource(R.drawable.sample_image);
}

这在可运行方法下运行。这是我得到的 logcat:

V/Your Path: /mnt/sdcard/Echo/Images/
V/Your image filename: Awesome4 - 00:01.jpg
V/Your currentPosition: 00:01
V/Your Path Playback edit: /mnt/sdcard/Echo/Images/
E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: /mnt/sdcard/Echo/Images/Awesome4 - 00:01.jpg: open failed: ENOENT (No such file or directory)
I/System.out: resolveUri failed on bad bitmap uri: /mnt/sdcard/Echo/Images/Awesome4 - 00:01.jpg
D/dalvikvm: GC_CONCURRENT freed 380K, 14% free 3067K/3560K, paused 74ms+3ms, total 226ms
V/Your image filename: Awesome4 - 00:02.jpg
V/Your currentPosition: 00:02
V/Your Path Playback edit: [ 06-27 04:14:07.691 6043: 6043 E/BitmapFactory ]
/mnt/sdcard/Echo/Images/Awesome4 - 00:02.jpg: open failed: ENOENT (No such file or directory)

最佳答案

check this if it helps you.

preview.setImageURI(Uri.parse(Environment.getExternalStorageDirectory().getAbsolutePath()+"/Echo/Images/"+file_name));

that how i do it...

public final static String APP_PATH_SD_CARD = "/DesiredSubfolderName/";
public final static String APP_THUMBNAIL_PATH_SD_CARD = "thumbnails";

public boolean saveImageToExternalStorage(Bitmap image) {
String fullPath = Environment.getExternalStorageDirectory().getAbsolutePath() + APP_PATH_SD_CARD + APP_THUMBNAIL_PATH_SD_CARD;

try {
File dir = new File(fullPath);
if (!dir.exists()) {
dir.mkdirs();
}

OutputStream fOut = null;
File file = new File(fullPath, "desiredFilename.png");
file.createNewFile();
fOut = new FileOutputStream(file);

// 100 means no compression, the lower you go, the stronger the compression
image.compress(Bitmap.CompressFormat.PNG, 100, fOut);
fOut.flush();
fOut.close();

MediaStore.Images.Media.insertImage(context.getContentResolver(), file.getAbsolutePath(), file.getName(), file.getName());

return true;

} catch (Exception e) {
Log.e("saveToExternalStorage()", e.getMessage());
return false;
}
}

关于android - 使用外部存储文件的路径设置 ImageView 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17334529/

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