Getting error: external allocation too large for this process

Go To StackoverFlow.com

1

I am trying to implement the code below converting a image path into a bitmap to display on my activity. I am getting the below error. I have tried a bunch of different solutions but none are working

Strange out of memory issue while loading an image to a Bitmap object

Android: Resize a large bitmap file to scaled output file

OutOfMemoryError: bitmap size exceeds VM budget :- Android

Error: E/dalvikvm-heap(19252): 12742656-byte external allocation too large for this process.

for(int i = 0; i < numItems; i++) {

     File imgFile = new  File(photoPaths.get(i));

        if(imgFile.exists())
        {

             images[i] = BitmapFactory.decodeFile(imgFile.getAbsolutePath());


        }
2012-04-03 21:30
by user182192
Try harder? I know for a fact that this one works: http://stackoverflow.com/questions/477572/android-strange-out-of-memory-issue-while-loading-an-image-to-a-bitmap-object/823966#82396 - dmon 2012-04-03 21:33


1

You may consider loading them in a more just-in-time kind of approach, or using the inSampleSize option of the bitmap factory (i.e., you'd pass a BitmapFactory.Options in to the factory with inSampleSize set to, ideally, a power of 2). Also make sure you set inPurgeable true.

In the event that you are pulling these images from the MediaStore's ContentProvider, you can also use thumbnails.

Perhaps you can tell us more about your use case so we can better help.

2012-04-03 21:49
by Jon O
Thumbs up for the inPurgeable=true suggestio - Mina Samy 2012-06-04 10:04


0

You're trying to load multiple large bitmaps, at least one of which is ~12MB. They're too large. The solutions you posted DO work. Resize your bitmaps to something much smaller, especially as you're just displaying the bitmaps on the screen.

2012-04-03 21:36
by kabuko
Ads