0

Getting this

05-25 23:55:59.145: ERROR/AndroidRuntime(3257): java.lang.OutOfMemoryError: bitmap size exceeds VM budget

at this code of mine -

Bitmap cs = null;

    cs = Bitmap.createBitmap(frameImg.getWidth(), frameImg.getHeight(), Bitmap.Config.ARGB_8888);

in activity class. How to fix this :(

nasaa
  • 2,701
  • 8
  • 47
  • 76
  • Well, how big is `frameImg`? If it's huge, then you'll need to come up with a better way to do whatever it is you're doing... – Ry- May 25 '11 at 23:04

5 Answers5

3

I ran into a similar problem when selecting images from my EVO ... off the SD Card. The camera saves those images at over 1MB a piece, and in some cases close to 3 MB. Ironically, the size of the bitmap the Intent sends to you when "taking a picture" is only about 40 Kb.

The solution I came up with was:

BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;    // this will cut the sampling by 50%
Bitmap bitmap = BitmapFactory.decodeFile( imageFilePath, options );

I was able to take pictures and cut them down to less than 100 Kb by increasing the factor number, and the images were still pretty good quality.

The bottom line here is it prevented OOME errors, and thus prevent me from crushing the JVM by exceeding the heap allocation. Simple - effective.

You might find this an interesting read also: BitmapFactory OOM driving me nuts

Community
  • 1
  • 1
BonanzaDriver
  • 6,411
  • 5
  • 32
  • 35
  • The way I explain it to people is "it's like reading a book whereby you skip every other line ... you still understand the essence of the story, but you give up some details in the process." – BonanzaDriver May 27 '11 at 16:43
1

Make the bitmap smaller in resolution and potentially use a different file format..

Manfred Moser
  • 29,539
  • 13
  • 92
  • 123
0

If the image is really big then you should just display the parts you need.

Robert Massaioli
  • 13,379
  • 7
  • 57
  • 73
0

Android has a relatively limited amount of spare of memory for bitmaps (which can get smaller depending on what else is going on in the device). So the other answers are correct...

  • scale the bitmap down (in pixels or resolution)
  • only display the subset of teh bitmap that is visible to the user.

Check out Displaying a bitmap of arbitrary size without running out of memory for background on what's going on under the covers - which might help you avoid the OOM.

Community
  • 1
  • 1
Torid
  • 4,176
  • 1
  • 28
  • 29
0

hi @user418366 i was having the same problem when dealing with images what you can do is if you are using the emulator you can rise the max VM application Heap size so that you can get override of this problem or else as told by all try to compress the size of the image make sure that it was a loss less compression

Karthik
  • 391
  • 4
  • 14