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

Thank you for visiting the BlackBerry Support Community Forums.

BlackBerry will be closing the BlackBerry Support Community Forums Device Forums on April 1st (Developers, see below)

BlackBerry remains committed to providing excellent customer support to our customers. We are delighted to direct you to the CrackBerry Forums, a well-established and thorough support channel, for continued BlackBerry support. Please visit http://forums.crackberry.com or http://crackberry.com/ask. You can also continue to visit BlackBerry Support or the BlackBerry Knowledge Base for official support options available for your BlackBerry Smartphone.

"When we launched CrackBerry.com 10 years ago, we set out to make it a fun and useful destination where BlackBerry Smartphone owners could share their excitement and learn to unleash the full potential of their BlackBerry. A decade later, the CrackBerry community is as active and passionate as ever and I know our knowledgeable members and volunteers will be excited to welcome and assist more BlackBerry owners with their questions."

- Kevin Michaluk, Founder, CrackBerry.com

Developers, for more information about the BlackBerry Developer Community please review Join the Conversation on the BlackBerry Developer Community Forums found on Inside BlackBerry.

Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Conversion from bitmap object to bitmap image

Hi guys,


I captured the screenshot of device. This is like a bitmap object. I need to convert from this bitmap object to bitmap image. Is it possible in Blackberry?


Please help me out through this. 


Thanks in advance,



Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Conversion from bitmap object to bitmap image

Can you confirm exactly what you mean by a bitmap image?  Are you talking about a stream of bytes in .bmp format?
Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Re: Conversion from bitmap object to bitmap image

Yes i need ".bmp" format.


Bitmap bitmap = new Bitmap(width, height);



After taking the screenshot I can convert from bitmap object(screen captured data) to ".JPG" and ".PNG" image format also using this JPEGEncodedImage.encode(bitmap)


But BMPEncodedImage doesn't have encode method so i am getting byte from bitmap object


byte[] _bytes = getBytesFromBitmap(bitmap);


BMPEncodedImage.createEncodedImage(_bytes ,0,_bytes .length);


while am using this method its throws "IllegalArgumentException".

Then using Fileconnection to save the image in device memory.


public byte[] getBytesFromBitmap(Bitmap bmp) {
            try {
                int height=bmp.getHeight();
                int width=bmp.getWidth();
                int[] rgbdata = new int[width*height];
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                DataOutputStream dos = new DataOutputStream(bos);
                Graphics g = new Graphics(bmp);
                for (int i = 0; i < rgbdata.length ; i++) {
                    if (rgbdata[i] != -1) {
                return bos.toByteArray();
            catch (Exception ex) {
                Dialog.alert("getBytesFromBitmap: " + ex.toString());
                return null;

I need to know whether Blackberry supports saving the captured image into raw BMP format. Also, can we directly capture images into a specified format like 1bit, 4bit mono, 4bit color, 8bit, 16bit etc..   

BlackBerry Development Advisor
Posts: 15,884
Registered: ‎07-09-2008
My Device: BlackBerry PRIV
My Carrier: Bell

Re: Conversion from bitmap object to bitmap image

You can use the getARGB method to get the raw data for the bitmap.  This can be used to create a new bitmap object.  The BlackBerry API set does not support encoding of bitmaps in a specific format.
Mark Sohm
BlackBerry Development Advisor

Please refrain from posting new questions in solved threads.
Problem solved? Click the Accept As Solution button.
Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Re: Conversion from bitmap object to bitmap image

Thanks for your reply MSohm. I get the new bitmap object using getARGB method as i mentioned in previous message. Then i am trying to get the ".bmp" image using FileConnection like this


byte[] ba = getBytesFromBitmap(image);//new bitmap object using getARGB method 


         fconn = (FileConnection)Connector.open("file:///store/home/user/screenCapture/mono"+ count +".bmp" , Connector.READ_WRITE);  
          if(!fconn.exists()) {
          o = fconn.openOutputStream();    
          //System.out.println("Data : " + ba);
catch(Exception ee){
       System.out.println("Exception in FileConnection : " + ee);
finally {
      try {                               
      catch(Exception e){
             System.out.println("Could not close File Connection : " + e);


i am not getting the ".bmp" image. can you pls clarify whether this raw data contains the header & color palette info? Because as you know to create the ".bmp" image, we need the header and color palette info.

New Developer
Posts: 6
Registered: ‎11-01-2009
My Device: Not Specified

Re: Conversion from bitmap object to bitmap image


is it possible to use this to get raw image data from the camera sensor in an 8320?

At least a bitmap before the noise-reduction step?


If so can you give me an idea of how to develop code for this in netbeans/ubuntu?