07-06-2013 12:57 PM
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();
Solved! Go to Solution.
07-06-2013 02:35 PM
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());
07-06-2013 04:15 PM
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?
07-06-2013 07:27 PM
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.