我碰到我的资产文件夹一些图片,我有这样的例外:
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