android OutOfMemoryError on WVGA800 and not any small screen format
When I try and decode a bitmap on an emulator running less than WVGA800 it works fine (phones included) but on larger screens it throws a OutOfMemoryError
Why would that be? would phones with larger screens have more memory?
private Bitmap getBitmap(int开发者_运维问答 assetKey) { return BitmapFactory.decodeResource(mContext.getResources(), assetKey); }
Phones with larger displays don't always have more memory than phones will smaller displas. Decoded bitmaps take a lot of of memory, 4 bytes of memory per pixel.
In general it is a good idea to downsample the bitmap if they are too large. You can do this easily:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inSampleSize = n; // <-- this only decode every nth pixel
Bitmap b = BitmapFactory.decodeResource(mContext, rId, ops);
It's generally a good practice to break the data in to samples, to avoid memory exception. you can see the following link for that. you have to use sampleSize more than 1. I have resolved my issues by following this post.
Strange out of memory issue while loading an image to a Bitmap object
精彩评论