×
Namespaces

Variants
Actions
Revision as of 07:42, 11 September 2009 by vaibhavjain (Talk | contribs)

How to calculate memory used by images in Java ME

From Nokia Developer Wiki
Jump to: navigation, search



Article Metadata
Tested with
Devices(s): S60,S40 All
Compatibility
Platform(s): MIDP 2.0
Series 40
Symbian
MIDP 2.0
Article
Keywords: Memory, Usage
Created: (09 Sep 2009)
Last edited: vaibhavjain (11 Sep 2009)

In the Forum several people encounter the "Out of Memory" Exception when running their MIDlets containing many Images and/or a single big Image.


Most of the time (even the big Images) the file-size of the Images wouldn't necessarily be expected to be a problem within the application Memory Usage. This is because people assume that a 7 kilobyte Image which is a 240x320 pixels plain white Image shouldn't create any memory problem, after all it's just 7 kilobyte, right ? Well, unfortunately, this is a wrong assumption !




Internally the OS will create a Bitmap-type mapping of the Image to be able to actually display it. This means that the mentioned 240x320 pixels Image will, depending on the screens color bit depth :

width * height * (color depth/8)

Let's say we got a 16 bit screen and a 320 x 240 pixels Image, this will result in :

320 * 240 * 2 = 153600 bytes ! Exactly 150 Kilobyte, which is a lot more than the 7 Kilobyte of the original Image file-size !



So now that you know what the size and memory usage of an Image means for you as a developer you will be more aware on how to use Images and know what the impact of an Image might be on the memory usage of your application !

125 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×