2013-06-27 72 views
4

您好我想更改我的ImageView的圖像使用我保存在我的SQLite數據庫的路徑。那麼我想實現的是每當圖像可用時每秒運行一次,它將顯示並保持到下一幅圖像可用。但是,只要沒有任何東西可以顯示,就會使用默認圖像。但現在我想解決的主要問題是我無法使用我擁有的路徑設置imageView。我嘗試了不同的解決方案,如從路徑製作出位,但仍然收到了同樣的錯誤是: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)使用來自外部存儲器的文件路徑設置ImageView圖像

這裏是我的代碼,截至目前:

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) 

回答

6

檢查這一點,如果它可以幫助你。

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

我不知道怎麼做...

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; 
} 
} 
+0

其實我只有這一個一個評論。它應該限制輸入文本,因爲文件名中不允許使用某些特殊字符。 :))無論如何,這有助於我意識到當時的錯誤。 :) – KaHeL

相關問題