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 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,

 

 

Please use plain text.
Developer
peter_strange
Posts: 19,601
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?
Please use plain text.
Developer
aykarthik
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);

Display.screenshot(bitmap);

 

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);
                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();
                        //l++;
                    }
                }
                bos.flush();
                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..   

Please use plain text.
Administrator
MSohm
Posts: 14,517
Registered: ‎07-09-2008
My Device: BlackBerry Z30, BlackBerry PlayBook
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.
Found a bug? Report it using Issue Tracker
Please use plain text.
Developer
aykarthik
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 

 

try{
         fconn = (FileConnection)Connector.open("file:///store/home/user/screenCapture/mono"+ count +".bmp" , Connector.READ_WRITE);  
                       
          if(!fconn.exists()) {
                  fconn.create();
                  //fconn.mkdir();                        
          }              
          o = fconn.openOutputStream();    
          o.write(ba);
          //System.out.println("Data : " + ba);
}
catch(Exception ee){
       System.out.println("Exception in FileConnection : " + ee);
}
finally {
      try {                               
             o.close();
             fconn.close();
      }
      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.

Please use plain text.
New Developer
touristguy87
Posts: 6
Registered: ‎11-01-2009
My Device: Not Specified

Re: Conversion from bitmap object to bitmap image

Hi,

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?

 

thanks

Please use plain text.