android大圖片顯示

 一般用攝像頭拍攝的圖片都會大於1M,

在anroid中載入這種大圖片的時候很容易內存不足,
這時候我們可以對大圖進行縮放,普通的圖片則正常顯示
 
  1. File file = new File(path); 
  2. byte[] all=...;//path文件的byte 
  3. if(file.length()>1024*1024){ 
  4.     BitmapFactory.Options options=new BitmapFactory.Options(); 
  5.         options.inSampleSize=10;//圖片縮放比例 
  6.         bmp = BitmapFactory.decodeByteArray(all, 0, all.length,options); 
  7. }else
  8.     bmp = BitmapFactory.decodeByteArray(all, 0, all.length); 
  9. mImageView.setImageBitmap(bmp); 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章