how to avoid outofmemory error android
Hai Friends, 开发者_StackOverflow中文版 i am trying to load 20 images.I get outofmemory error. how to avoid outof memory error .plz help me;
Kanivel,
Assuming its absolutely necessary that you load 20 images at once you may need to scale the images to prevent your Heap from growing too large.
This is implemented with the inSampleSize
option in BitmapFactory
. Documentation here: http://developer.android.com/reference/android/graphics/BitmapFactory.Options.html#inSampleSize
Here is a quick example of its use in my code:
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 16;
Bitmap image= BitmapFactory.decodeFile(imageFilePath, options);
My example will get you an image that is 1/16th the original size and contains 1/256th the original pixels. My implementation is for making thumbnails out of large photos.
Your device doesn't have enough memory to load 20 images.
You should load fewer images, or make the images smaller.
精彩评论