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
New Contributor
artr
Posts: 7
Registered: ‎07-06-2013
My Device: 8520
My Carrier: Maxis
Accepted Solution

is there any equivalent code of this?

Hi, I am doing a project on steganography, but i am stuck on converting bitmap to byte array.

There is no problem for the code to run in desktop. Is there any equivalent code for the following code in BlackBerry JDE (for OS 5)?

 

private byte[] imageToByte(BufferedImage img)
{
WritableRaster raster = img.getRaster();
DataBufferByte buffer = (DataBufferByte)raster.getDataBuffer();
return buffer.getData();
}

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: is there any equivalent code of this?

Look at Bitmap getARGB(...) method.

 

Here is some sample code form the Bitmap documentation:

 

 Bitmap original = ....

 int[] argb = new int[original.getWidth() * original.getHeight()];
 original.getARGB(argb, 0, original.getWidth(), 0, 0, original.getWidth(), original.getHeight());

Please use plain text.
New Contributor
artr
Posts: 7
Registered: ‎07-06-2013
My Device: 8520
My Carrier: Maxis

Re: is there any equivalent code of this?

I got it! thanks. But the number of size of array in using Bitmap.getARGB and DataBufferByte is different by 3x (ie. 400 in argb but 1200 in databufferbyte). What cause this?

 

And is there anyway to convert back from byte array to bitmap?

Please use plain text.
Developer
peter_strange
Posts: 19,599
Registered: ‎07-14-2008
My Device: Not Specified

Re: is there any equivalent code of this?

Ah, answered the wrong question.

 

You need to decide what format you want the bytes in, then look for the EncodedImage format that matches.

 

Say you wanted a png file, then convert the Bitmap to a PNGEncodedImage, using encode, and from there you can do a getBytes().  That should do it for you. 

Please use plain text.