首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

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

2012-06-27 
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) {}

热点排行