OutOfMemoryError:位图大小超过VM预算: - Android

And*_*ndy 60 android bitmap out-of-memory

可能重复:
Android:将图像加载到Bitmap对象时出现奇怪的内存不足问题

我正在从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();
Run Code Online (Sandbox Code Playgroud)

这是错误: 05-28 14:55:47.251: ERROR/AndroidRuntime(4188): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

San*_*ndo 31

使用decodeStream(is, outPadding, opts)

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]; 
Run Code Online (Sandbox Code Playgroud)

  • 谢谢,几个月来一直在寻找解决方案 (2认同)

Sam*_*muh 5

您可以检查图像大小,然后按适当的因子对其进行下采样.

看到这个问题:处理大型位图


Sep*_*phy 2

这个问题似乎已经被报道过好几次了,例如在这里这里......对不起,Shalini,但如果是同样的问题,似乎根本没有解决方案......

Romain Guy 唯一的建议是使用更少的内存......

所以,祝你好运,以不同的方式思考你的事情......

  • 有一个解决方案:使用少于允许的最大内存。我知道这是一个令人沮丧的答案,但手机不像台式机那样拥有“无限”的 RAM。你必须要小心。 (3认同)