Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Posts: 98
Registered: ‎01-06-2009
My Device: Pearl 8110
Accepted Solution

Bugs In EncodedImage and BitmapField

Hi guys,


I've been have trouble scaling down a large image (1600x1200) taken

w/ BB camera to fit on the Pearl. I use EncodedImage api to scale it

and pass it to BitmapField. But this cause a system restart. When I

use BitmapField with the image w/O rescaling, I will get an out of memory

exception and my app will not run again.  BitmapField will work w/ only

small images. 

Posts: 1,123
Registered: ‎02-10-2009
My Device: 8130 / 8350 / 9530 / 9550 / 9850 / PlayBook
My Carrier: Verizon

Re: Bugs In EncodedImage and BitmapField

[ Edited ]

I had an issue with this, and it seems that on certain devices an arithmatic error will cause the device to reboot. It is probably due to an incorrect size argument on the Bitmap you generate. The getWidth() and getHeight() values will return a Fixed32 value with whatever height and width the scaling of the image produces (even if it is wrong). I resolved the issue by wrapping all the numbers in a Fixed32 object and using the Fixed32.div() method.




Bitmap b = EncodedImage.getEncodedResource("myImage.png").scale32( Fixed32.div( Fixed32.toFP(1600), Fixed32.toFP(w_scale) ), 

                                                                                                             Fixed32.div( Fixed32.toFP(1200), Fixed32.toFP(h_scale) ) );

Message Edited by CMY on 07-18-2009 08:04 PM
Posts: 98
Registered: ‎01-06-2009
My Device: Pearl 8110

Re: Bugs In EncodedImage and BitmapField

Thanks for help. I am playing with EncodedImage and Bitmap classes and BitmapField.

The scaling works in that I do get the correct width and height for my device

but when I pass an EncodedImage object to Bitmap object, it doesn't keep 

the scaled image. Bitmap object has its own scaling parameter that's doesn't

bare good documentation. I don't think going from EncodedImage --> Bitmap -->BitmapField

isn't a good path. I doing looking into paint the scale image manually by override the paint field method.