一般用攝像頭拍攝的圖片都會大於1M,
在anroid中載入這種大圖片的時候很容易內存不足,
這時候我們可以對大圖進行縮放,普通的圖片則正常顯示
File file = new File(path);
byte[] all=…;//path文件的byte
if(file.length()>1024*1024){
BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize=10;//圖片縮放比例
bmp = BitmapFactory.decodeByteArray(all, 0, all.length,options);
}else{
bmp = BitmapFactory.decodeByteArray(all, 0, all.length);
}
mImageView.setImageBitmap(bmp);
本文出自 “魚骨頭” 博客