读书人

Android中Bitmap的java.lang.OutOfMem

发布时间: 2012-06-27 14:20:09 作者: rapoo

Android中Bitmap的java.lang.OutOfMemoryError问题解决(转载)


无用的bitmap最好先Bitmap.recycle()回收空间。

动态计算出图片的inSampleSize。
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inJustDecodeBounds = true;BitmapFactory.decodeFile(imageFile, opts);
opts.inSampleSize = computeSampleSize(opts, -1, 128*128);
opts.inJustDecodeBounds = false;
try {
Bitmap bmp = BitmapFactory.decodeFile(imageFile, opts);
imageView.setImageBitmap(bmp);
} catch (OutOfMemoryError err) {}

读书人网 >Ruby Rails

热点推荐