gpt4 book ai didi

android - OutOfMemoryError : bitmap size exceeds VM budget :- Android

转载 作者:IT老高 更新时间:2023-10-28 13:23:34 25 4
gpt4 key购买 nike

Possible Duplicate:
Android: Strange out of memory issue while loading an image to a Bitmap object

我正在从 Url 下载图像并显示它们。在下载时它给内存不足错误:位图大小超出 VM 预算。我正在使用可绘制的。代码如下:

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`

最佳答案

使用 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];

关于android - OutOfMemoryError : bitmap size exceeds VM budget :- Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2928002/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com