0

Hai Friends, i am trying to load 20 images.I get outofmemory error. how to avoid outof memory error .plz help me;

0

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

Your device doesn't have enough memory to load 20 images.

You should load fewer images, or make the images smaller.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.