通过BitmapFactory.decodeByteArray把byte[]转成Bitmap出现的OOM的解决方法
(2016-06-01 21:29:51)分类: android |
原文:http://blog.csdn.net/tangqq1987108/article/details/39521561
、
-
public
static Bitmap byte[]byteToBitmap( imgByte) { -
InputStream input = null; -
Bitmap bitmap = null; -
BitmapFactory.Options options = new BitmapFactory.Options(); -
options.inSampleSize = 8; //设置为原图片的1/8,以节省内存资源 -
input = new ByteArrayInputStream(imgByte); -
SoftReference softRef = new SoftReference(BitmapFactory.decodeStream( -
input, null, options)); //软引用 -
bitmap = (Bitmap) softRef.get(); -
if (imgByte null)!= { -
imgByte = null; -
} -
-
try { -
if (input null)!= { -
input.close(); -
} -
} catch (IOException e) { -
// TODO Auto-generated catch block -
e.printStackTrace(); -
} -
return bitmap; -
}