我有這段代碼從SD卡檢索圖像。但它沒有在ImageView
中顯示任何圖片。我確信SD卡上有圖像。如何從SD卡檢索圖像
File f = new File("/mint/sdcard/e.jpg");
Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
Toast.makeText(this, bitmap + "", 3).show();
bmImage.setImageBitmap(bitmap);
我有這段代碼從SD卡檢索圖像。但它沒有在ImageView
中顯示任何圖片。我確信SD卡上有圖像。如何從SD卡檢索圖像
File f = new File("/mint/sdcard/e.jpg");
Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
Toast.makeText(this, bitmap + "", 3).show();
bmImage.setImageBitmap(bitmap);
更改像這樣,
File f = new File("/mnt/sdcard/e.jpg");
Bitmap bitmap = BitmapFactory.decodeFile(f.getAbsolutePath());
bmImage .setImageBitmap(bitmap);
提到OP是什麼改變了(雖然你上面評論) – KevinDTimm
它不是mint
其mnt
。讓你的線,
File f = new File("/mnt/sdcard/e.jpg");
public Bitmap readImageFromExternalMemory(String name) throws IOException
{
File file = new File(Environment.getExternalStorageDirectory().toString()+"/"+name, userId + ".jpg");
FileInputStream inStream = new FileInputStream(file);
Bitmap bitmap = BitmapFactory.decodeStream(inStream);
inStream.close();
return bitmap;
}
您不必使用"/mnt/sdcard/e.jpg"
。您必須使用此方法:
Environment.getExternalStorageDirectory().toString()
因爲它將返回正確的外部目錄路徑。製造商可以將其重命名爲其他內容,因此您必須使用上述方法。
的最好的事情就是用這樣的:
File sdcard = Environment.getExternalStorageDirectory();
File f = new File(sdcard+"/e.jpg");
現在它適用於所有Android手機
它不是'mint'其'mnt' – Vinay
不薄荷,這是MNT。 –
寫入後仍然不能正常工作... – user1722376