Welcome!

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

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

Conversion from bitmap object to .bmp image

Hi Guys,

 

I am capturing the screen using the screenshot method of the Display class.Captured data like a Bitmap object. I need to get directly from Bitmap object to ".bmp" image without convertion of JPEGEncodedImage or PNGEncodedImage.

 

After capturing the screen i call the below method to convert the Bitmap object to byte array.

 

byte[] byteArray = getBytesData(image);

 

public byte[] getBytesData(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);
                bmp.getARGB(rgbdata,0,width,0,0,width,height);
                for (int i = 0; i < rgbdata.length ; i++) {
                    if (rgbdata[i] != -1) {
                        dos.writeInt(i);                       
                        dos.flush();
                    }
                }
                bos.flush();                       
                return bos.toByteArray();
            }
            catch (Exception ex) {
                Dialog.alert("getBytesFromBitmap: " + ex.toString());
                return null;
            } 
 }     

 

 

Then I try to convert byte array to .bmp image using below step

 

EncodedImage  bmp =  BMPEncodedImage.createEncodedImage(ba,0,ba.length);

 

But Its throws IllegalArgumentsException. 

 

Is it correct way to convert bitmap objet to .bmp image?

else how to create .bmp image?

 

Please help me on this

 

 

Thanks in advance,

 

Please use plain text.
Developer
Artem
Posts: 53
Registered: ‎12-11-2008
My Device: Not Specified

Re: Conversion from bitmap object to .bmp image

[ Edited ]

Please see documentation for EncodedImage. EncodedImage class is used to read images in various formats - not to write.

Here is the link how to convert Bitmap to BMP buffer: http://en.wikipedia.org/wiki/BMP_file_format.

I would provide you with the code, but I have only C/C++ code for this stuff.

Message Edited by Artem on 12-17-2008 05:11 AM
Please use plain text.
Developer
aykarthik
Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Re: Conversion from bitmap object to .bmp image

Thanks for your reply. 

 

If any one knows the solution for this conversion. Please help me.

 

 

Please use plain text.
Developer
Guest
Posts: 146
Registered: ‎11-05-2008
My Device: Not Specified

Re: Conversion from bitmap object to .bmp image

have you used Bitmap.createBitmapFromBytes(abytes, 0, length, 1)?I have used it for png,gif and jpg.it was ok for these file type.But i m not sure about bmp file type.
Please use plain text.
Developer
aykarthik
Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Re: Conversion from bitmap object to .bmp image

Thanks for your reply.

 

I think this method is used to get the bitmap image from server data.

 

I need reverse process of this. 

 

Please use plain text.
Developer
Artem
Posts: 53
Registered: ‎12-11-2008
My Device: Not Specified

Re: Conversion from bitmap object to .bmp image

I can provide you with C/C++ code and all you will need is just to rewrite it.

 

Please use plain text.
Developer
aykarthik
Posts: 187
Registered: ‎08-13-2008
My Device: Not Specified

Re: Conversion from bitmap object to .bmp image

Thanks Artem, i got the C/C++ code from your previous reply using this thread http://www.kalytta.com/bitmap.h

 

If you think it is not correct please send me your C/C++ code.

Please use plain text.