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

Android中Bitmap的java.lang.OutOfMemoryError问题解决(转载)无用的bitmap最好先Bitmap.recycle()回收空间

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) {}