zoukankan      html  css  js  c++  java
  • 通过BitmapFactory.decodeByteArray把byte[]转成Bitmap出现的OOM的解决方法

    使用Bitmap mBitmap = BitmapFactory.decodeByteArray(data, 0, data.length)来转成Bitmap的时候,老报OOM,在网上也找了很多关于优化OOM的方法。

    最后,采用了以下方法后,再也没有报OOM了


    [java] view plain copy
    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;  
    6.         input = new ByteArrayInputStream(imgByte);  
    7.         SoftReference softRef = new SoftReference(BitmapFactory.decodeStream(  
    8.                 input, null, options));  
    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.     }  
  • 相关阅读:
    linux 硬件信息
    docker note
    Shell cmd set note
    mysql management note
    scp noneed passwd
    update kernel
    数据包处理过程
    tcp/ip分片
    sockopt note
    Python note
  • 原文地址:https://www.cnblogs.com/vegetate/p/9997255.html
Copyright © 2011-2022 走看看