可能是重复问题:
Android:在将图像加载到位图对象时出现奇怪的内存不足问题
我正在从 URL 下载图片并将它们显示出来。在下载时,出现了“out of memory error : bitmap size exceeds VM budget”的错误。我正在使用 drawable。下面是代码:
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`
img = Bitmap.createBitmap(size.x, size.y, Bitmap.Config.ARGB_8888);
) 它会崩溃怎么办? - ManuelcreateScaledBitmap
后调用bitmap.recycle
时,要确保要回收的位图对象不是刚刚获取的那个对象。Android文档中指出:如果指定的宽度和高度与源位图的当前宽度和高度相同,则返回源位图,并且不会创建新的位图。 - philipp