Reputation: 1633
Hai Friends, i am trying to load 20 images.I get outofmemory error. how to avoid outof memory error .plz help me;
Upvotes: 0
Views: 598
Reputation: 33509
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.
Upvotes: 2
Reputation: 887215
Your device doesn't have enough memory to load 20 images.
You should load fewer images, or make the images smaller.
Upvotes: 1