OOM
来源:互联网 发布:双系统mac开机密码忘了 编辑:程序博客网 时间:2024/05/08 03:46
I come from iOS experience and I was frustrated to discover such a pathetic issue with something so basic as loading and showing an image. After all, everyone that is having this issue is trying to display reasonably sized images. Anyway, here are the two changes that fixed my problem (and made my app very responsive).
1) Every time you do BitmapFactory.decodeXYZ()
, make sure to pass in aBitmapFactory.Options
with inPurgeable
set to true
(and preferably withinInputShareable
also set to true
).
2) NEVER use Bitmap.createBitmap(width, height, Config.ARGB_8888)
. I mean NEVER! I've never had that thing not raise memory error after few passes. No amount of recycle()
,System.gc()
, whatever helped. It always raised exception. The one other way that actually works is to have a dummy image in your drawables (or another Bitmap that you decoded using step 1 above), rescale that to whatever you want, then manipulate the resulting Bitmap (such as passing it on to a Canvas for more fun). So, what you should use instead is:Bitmap.createScaledBitmap(srcBitmap, width, height, false)
. If for whatever reason you MUST use the brute force create method, then at least pass Config.ARGB_4444
.
This is almost guaranteed to save you hours if not days. All that talk about scaling the image, etc. does not really work (unless you consider getting wrong size or degraded image a solution).
But google, seriously?
BitmapFactory.Options options = new BitmapFactory.Options(); options.inPurgeable = true;
and Bitmap.createScaledBitmap(srcBitmap, width, height, false);
solved my issue I had with out of memory exception on android 4.0.0. Thanks mate!
- OOM
- OOM
- OOM
- OOM
- OOM
- oom
- OOM
- oom
- oom
- OOM
- oom
- OOM
- OOM
- oom
- oom
- OOM
- OOM killer
- oom killer
- C++ 继承成员访问控制机制
- org.apache.commons.io.FileUtils使用详解
- hadoop作业调优参数整理及原理
- twitter分享——采用第三方库sharekit(附Demo)
- oracle 监听日志文件过大,导致监听无法启动
- OOM
- HEVC-编码器入口
- 求两个字符序列的最大公共子序列
- java函数的复写(第20集)
- 为什么使用数组?
- [算法] doj 1066 最长上升子序列
- Mapreduce-Partition分析
- C# DataTableー>CSVー>DB
- 从图片的拓展名获取系统内置编码器的CLSID