超出内存与位图9830416字节分配 [英] Out of memory on a 9830416-byte allocation with bitmap

查看:169
本文介绍了超出内存与位图9830416字节分配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我碰到我的资产文件夹一些图片,我有这样的例外:

I'm getting some image from my assets folder, and I have this exception:

03-11 10:18:28.019: E/dalvikvm-heap(4052): Out of memory on a 9830416-byte allocation.

我有这个错误的位置:

I have this error here :

//stream to get photo
InputStream bitmap=null;                        
bitmap=getResources().getAssets().open("ProduitsMini/"+productList.get(rang).getImg_mini());
Bitmap bit=BitmapFactory.decodeStream(bitmap);

// get drawable image
Drawable mDrawable = new BitmapDrawable(getResources(),bit);

这很奇怪,因为我必须在每台设备上没有这个错误,但只有银河S3。

It's strange because I haven't this error on each device, but only with Galaxy S3.

推荐答案

您可以尝试添加低于code

You can try adding below code

InputStream bitmap=null; 
bitmap=getResources().getAssets().open("ProduitsMini/"+productList.get(rang).getImg_mini());

BitmapFactory.Options options=new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap preview_bitmap = BitmapFactory.decodeStream(bitmap,null,options);

这个inSampleSize选项可减少内存消耗。

This inSampleSize option reduces memory consumption.

您可以参考以下链接

http://stackoverflow.com/a/823966/1441666

这篇关于超出内存与位图9830416字节分配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆