我試圖從現有文件路徑創建一個位圖或Drawable。創建一個位圖/從文件路徑繪製
String path = intent.getStringExtra("FilePath");
BitmapFactory.Options option = new BitmapFactory.Options();
option.inPreferredConfig = Bitmap.Config.ARGB_8888;
mImg.setImageBitmap(BitmapFactory.decodeFile(path));
// mImg.setImageBitmap(BitmapFactory.decodeFile(path, option));
// mImg.setImageDrawable(Drawable.createFromPath(path));
mImg.setVisibility(View.VISIBLE);
mText.setText(path);
但setImageBitmap()
,setImageDrawable()
不顯示從路徑的圖像。我用mText
打印路徑,它看起來像:/storage/sdcard0/DCIM/100LGDSC/CAM00001.jpg
我在做什麼錯了?任何人都可以幫助我?
BitmapFactory.decodeFile(路徑) - >這是否返回一個位圖對象嗎?你能證實嗎? – toantran
@ autobot_101在調試模式下,它在'mBuffer'中有'id'。但是它的'mHeight','mWidth'值是'-1','mLayoutBounds'是'null'。 –
然後你應該再次檢查你的文件路徑,因爲這意味着你的圖像沒有被「膨脹」到位圖對象。也許你可以嘗試其他圖像 – toantran