Android ImageView setImageBitmap 不顯示圖片
阿新 • • 發佈:2018-01-24
true byte onf fig .config 顯示圖片 pri factory deb
從sd卡裏讀出圖片後有時調用setImageBitmap(bitmap)方法會顯示不出圖片,仔細考慮過後原來是加載的圖片過大導致的,解決辦法為:
BitmapFactory.Options op = new BitmapFactory.Options(); op.inSampleSize = 2; //op.inJustDecodeBounds = true; //它僅僅會把它的寬,高取回來給你,這樣就不會占用太多的內存,也就不會那麽頻繁的發生OOM了。 //op.inPreferredConfig = Bitmap.Config.ARGB_4444;// 默認是Bitmap.Config.ARGB_8888 private Bitmap createBitmapFromByteData(byte[] data ,Options options){ Bitmap bitmap = null; if(options == null){ bitmap = BitmapFactory.decodeByteArray(data, 0, data.length); }else{ bitmap = BitmapFactory.decodeByteArray(data, 0, data.length, options); } return bitmap; }
這樣返回的bitmap就可以被顯示出來了。
Android ImageView setImageBitmap 不顯示圖片