无用的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) {}
动态计算出图片的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) {}
本文探讨了如何在Android应用中优化图片加载效率并有效管理内存,通过动态计算inSampleSize来减小图片大小,避免因大图片导致的内存溢出问题。重点介绍了使用Bitmap类的recycle()方法释放不再使用的位图资源,以及如何利用BitmapFactory.Options类来实现内存友好的图片解码。
9831

被折叠的 条评论
为什么被折叠?



