2011-10-17 30 views
0

我的問題是我從圖片庫中獲取圖像&使用BitmapFactory.decodeResource()將圖像轉換爲位圖,但問題是圖像是在模擬器中獲取但不是在真實設備,在實際設備中,位圖值變爲空。以下是我解碼Gallery Image的代碼。使用BitmapFactory.decodeFile()但圖像不解碼

String Galleryimagepath="/mnt/sdcard/DCIM/.thumbnails/1308059312410.jpg";  
bmpImage = BitmapFactory.decodeFile(Galleryimagepath); 
drawable = new BitmapDrawable(bmpImage); 
mRlayoutmainimage.setBackgroundDrawable(drawable); 

任何幫助,將不勝感激。

+0

你爲什麼從縮略圖文件夾中獲取圖像,而不是實際的文件夾? – androidnoob

回答

1

Yashwanth是正確的,該路徑可以是設備和模擬器,進一步,路徑可能不同設備到設備以及不同。您最好獲取所需圖像的內容URI,並使用MediaStore.Images.Thumbnails.getThumbnail()獲取要查找的位圖。

MediaStore.Images.Thumbnails

0

我覺得真正的設備上的SD卡路徑是不同的。您可能需要使用類似

Environment.getExternalStorageState() 

請檢查以下鏈接。

Find an external SD card location

+0

我從Gallery Intent中獲取「/mnt/sdcard/DCIM/.thumbnails/1308059312410.jpg」路徑。 –

相關問題