2013-02-22 91 views
-3
String imageInSD = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg";   
Bitmap bitmap = BitmapFactory.decodeFile(imageInSD); 

if(bitmap == null){     
    Log.v("combine image", "null"); 
}else{ 
    Log.v("combine image", "not null");     
} 

更新:使用Environment.getExternalStorageDirectory()感謝您的信息BitmapFactory.decodeFile()返回null,當我試圖讓圖像

+0

所以你得到它的工作? – 2013-02-22 07:47:18

+0

嘗試:'String imageInSD = Environment.getExternalStorageDirectory()。getAbsolutePath()+ File.separator +「DCIM/Soovy/2089.jpg」;' – Akash 2013-02-22 07:48:00

+0

yes got is working and as aasasasia mentioned should use Environment.getExternalStorageDirectory() – jhdj 2013-02-22 09:38:17

回答

1

不要直接訪問SD卡,試圖通過Environment訪問它。

像這樣:

String imageDir = Environment.getExternalStorageDirectory()+"/DCIM/Soovy/2089.jpg"; 

Bitmap bitmap = BitmapFactory.decodeFile(imageDir); 

if(bitmap == null){     
    Log.v("combine image", "null"); 
}else{ 
    Log.v("combine image", "not null");     
} 
+0

Check他的更新.... – Pragnani 2013-02-22 07:55:09

+0

謝謝,也有幫助 – jhdj 2013-02-22 09:20:35

+0

最受歡迎:) – moDev 2013-02-22 09:48:07

0

試試這個:

String imageInSD = "file:///mnt/sdcard/DCIM/Soovy/2089.jpg";   

您應該然而,不是硬編碼路徑。使用

Environment.getExternalStorageState() 

得到sdcard的根。

String imageInSD = Environment.getExternalStorageState() + "/DCIM/Soovy/2089.jpg"; 
相關問題