忘记从哪看来的了,但是感觉挺好用的。
/**
*防止加载大图片时 ,oom错误
*/
public static Bitmap readBitMap(Context context, int resId) {
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
InputStream is = context.getResources().openRawResource(resId);
return BitmapFactory.decodeStream(is, null, opt);
}
本文介绍了一种有效防止加载大图片时出现内存溢出(OutOfMemory, OOM)错误的方法。通过设置BitmapFactory.Options参数,如inPreferredConfig、inPurgeable和inInputShareable等,可以有效地减少内存消耗并避免OOM错误的发生。
1336

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



