加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

通过BitmapFactory.decodeByteArray把byte[]转成Bitmap出现的OOM的解决方法

(2016-06-01 21:29:51)
分类: android
原文:http://blog.csdn.net/tangqq1987108/article/details/39521561
  1. public static Bitmap byteToBitmap(byte[] imgByte)  
  2.         InputStream input null 
  3.         Bitmap bitmap null 
  4.         BitmapFactory.Options options new BitmapFactory.Options();  
  5.         options.inSampleSize 8;  //设置为原图片的1/8,以节省内存资源
  6.         input new ByteArrayInputStream(imgByte);  
  7.         SoftReference softRef new SoftReference(BitmapFactory.decodeStream(  
  8.                 input, nulloptions));  //软引用
  9.         bitmap (Bitmap) softRef.get();  
  10.         if (imgByte != null 
  11.             imgByte null 
  12.          
  13.   
  14.         try  
  15.             if (input != null 
  16.                 input.close();  
  17.              
  18.         catch (IOException e)  
  19.             // TODO Auto-generated catch block  
  20.             e.printStackTrace();  
  21.          
  22.         return bitmap;  
  23.     }  

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有