Skip to main content

Error "java.lang.OutOfMemoryError: bitmap size exceeds VM budget" when trying to rotate image on lwuit android

5 replies [Last post]
bayu.utomo
Offline
Joined: 2011-10-24
Points: 0

Hi guys,

I got an error "bitmap size exceeds VM budget" when trying to rotate image on lwuit android using image.rotate(). It seems that the error is caused by executing :

Bitmap.createBitmap((Bitmap) image, 0, 0, ((Bitmap) image).getWidth(), ((Bitmap) image).getHeight(), matrix, true);

in the rotate method in the androidimplementation class.

anyone have some clue?

thanks for the advice

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
vprise
Offline
Joined: 2003-11-07
Points: 0

How big is the image? (width/height)

bayu.utomo
Offline
Joined: 2011-10-24
Points: 0

width 150 pixels and height 150 pixels. The image stored in the PNG format.

The code snippet looks like this:

Image origin_image = Image.createImage(activity.getResources().openRawResource(R.drawable.image1));
Image rotated_image = origin_image.rotate(60);

vprise
Offline
Joined: 2003-11-07
Points: 0

Why are you creating an image in this way and not using the LWUIT images?

You should place all images within the assets or the res file (with LWUIT) this will allow you to debug your code on J2SE/ME which provide a better means of detecting memory issues. I'm guessing that you are allocating lots of images and they aren't getting released for some reason but that's just a shot in the dark.

bayu.utomo
Offline
Joined: 2011-10-24
Points: 0

because I provide same image with different size in directory of "drawable-hdpi", "drawable-mdpi" and "drawable-ldpi" and I want android to detect the right image for the right screen size automatically through "R.drawable". and also because I think the image class in lwuit and android are different, so I use stream to convert from image class on android to image class on lwuit

vprise
Offline
Joined: 2003-11-07
Points: 0

LWUIT has the Multi-Image class that does the exact same thing and works across all platforms, I'm betting this is related to repeatedly loading the image with a stream and flooding the android device RAM.