Fallenreaper
Fallenreaper

Reputation: 10704

BitmapFactory for java gives a OutOfMemory Exception, wanting > 12mb... Not sure why it is sooo large

Having a OOM error with Bitmap factory for my android devices.

Out of memory on a 12582928-byte allocation.

which is weird to me. It is very large. THe files themselves, are images tank on the tablet and downloaded. So the images might reach a 1.2meg jpg or so at the upper bounds.

After it says that Error, it spits out the AndroidRuntime error log for a fatal exception:

10-01 11:53:52.512: E/AndroidRuntime(31023): FATAL EXCEPTION: Thread-7893
10-01 11:53:52.512: E/AndroidRuntime(31023): java.lang.OutOfMemoryError
10-01 11:53:52.512: E/AndroidRuntime(31023):    at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:582)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:380)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at com.bentley.cordova.plugins.ImageOps.createThumbnailForPath(ImageOps.java:43)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at com.bentley.cordova.plugins.ImageOps.execute(ImageOps.java:20)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at org.apache.cordova.api.PluginManager$1.run(PluginManager.java:192)
10-01 11:53:52.512: E/AndroidRuntime(31023):    at java.lang.Thread.run(Thread.java:856)

I Do have a lot of images processing with this function simultaneously. I didnt think the BitMapFactory was being overworked at all from the different threads running.

Upvotes: 0

Views: 264

Answers (2)

Tim Lamballais
Tim Lamballais

Reputation: 1054

Please consider the fact that a bitmap representation of a 1.2 MB JPEG image may easily (depending on its compression rate) exceed 12 MB.

When using 32bit color a bitmap takes at least width * height * 4 bytes to represent.

Even if a single instance does not exceed the 12MB mark, running this in a threaded manner may exceed the JVM's allocated max heap size.

Upvotes: 1

Blackbelt
Blackbelt

Reputation: 157467

So the images might reach a 1.2meg jpg or so at the upper bounds.

that's not true. A 32bit bitmap will require width * height * 4 bytes in order to be allocated. Remember to recycle your bitmap when you do not need it. Also downsample it, if you can

Upvotes: 3

Related Questions