可能的重复:
Android:将图像加载到位图对象时出现奇怪的内存不足问题 https://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object
我正在从 Url 下载图像并显示它们。在下载时它给出out of memory error : bitmap size exceeds VM budget
。
我正在使用可绘制的。代码如下:
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];
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)