In BlackBerry, is it better to use the Bitmap class or EncodedImage in terms of memory usage and performance? Are there any specific tips on using these classes?
Asked
Active
Viewed 2,455 times
7

Maksym Gontar
- 22,765
- 10
- 78
- 114

Prabhu R
- 13,836
- 21
- 78
- 112
-
2If your source image is actually a png, gif, jpeg, or whatever, you have to use EncodedImage. When you set a BitmapField, you can either create it with a Bitmap or set an EncodedImage later. Curiously, you can only set it focusable during creation, where Bitmap is required. Bitmap will use more memory (fully decoded image) unless EncodedImage internally also keeps a decoded copy (no idea -- could depend on the JDE version, too) but I have noticed getBitmap() is often very fast. You'd probably need to do your own profiling to see in your exact use case... – lilbyrdie Aug 21 '09 at 16:57
-
1Shouldn't that be an answer instead of a comment? :) – KarolDepka Aug 07 '11 at 21:38
1 Answers
7
My observation is that better:
- use Bitmap and drawBitmap for elements that require repaint often (ex background image in games)
Maybe it's because Bitmap is a raw format so no performance hit for decoding EncodedImage before drawImage. On the other side, GIF animation works perfectly with EncodedImage.
- use EncodedImage for animation or for a large amount of resources (ex photos or decore elements)
When you load Bitmap from gif, png, jpg formats they will be opened as an EncodedImage anyway, and if you do this many times, it may beat performance (ex 50 seconds to load 14 png from resources to Bitmaps on bold, avg size 80 kb, tuned up to 2 seconds loading into EncodedImages)
UPDATE stated by Fostah EncodedImage has a getBitmap() function that you can use to convert any EncodedImage to a Bitmap. So you can load in EncodedImage and then use as Bitmap

Community
- 1
- 1

Maksym Gontar
- 22,765
- 10
- 78
- 114