OutOfMemoryError:位图大小超出 VM 预算:- Android [英] OutOfMemoryError: bitmap size exceeds VM budget :- Android
本文介绍了OutOfMemoryError:位图大小超出 VM 预算:- Android的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能的重复:
Android:奇怪将图像加载到 Bitmap 对象时的内存问题
我正在从 Url 下载图像并显示它们.在下载时它给出内存不足错误:位图大小超出虚拟机预算
.我正在使用可绘制.代码如下:
i am downloading images from Url and displaying them. At download time it is giving
out of memory error : bitmap size exceeds VM budget
.
I am using drawable. Code is below:
HttpClient httpclient= new DefaultHttpClient();
HttpResponse response=(HttpResponse)httpclient.execute(httpRequest);
HttpEntity entity= response.getEntity();
BufferedHttpEntity bufHttpEntity=new BufferedHttpEntity(entity);
InputStream instream = bufHttpEntity.getContent();
Bitmap bm = BitmapFactory.decodeStream(instream);
Bitmap useThisBitmap =
Bitmap.createScaledBitmap(bm,bm.getWidth(),bm.getHeight(), true);
bm.recycle();
BitmapDrawable bt= new BitmapDrawable(useThisBitmap);
System.gc();
这里是错误:
`05-28 14:55:47.251: ERROR/AndroidRuntime(4188):
java.lang.OutOfMemoryError: bitmap size exceeds VM budget`
推荐答案
Use decodeStream(is, outPadding, opts)
with
BitmapFactory.Options opts=new BitmapFactory.Options();
opts.inDither=false; //Disable Dithering mode
opts.inPurgeable=true; //Tell to gc that whether it needs free memory, the Bitmap can be cleared
opts.inInputShareable=true; //Which kind of reference will be used to recover the Bitmap data after being clear, when it will be used in the future
opts.inTempStorage=new byte[32 * 1024];
这篇关于OutOfMemoryError:位图大小超出 VM 预算:- Android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文