I'm trying to convert the byte array into a bitmap, and then again I'm converting back from bitmap to byte array, but there seems to be some issue, because the images do not match.
Below is the function that I'm using to convert byte array to bitmap.
public Bitmap getBitmapFromRawImage(byte[] rawImage,int width,int height) {
byte[] Bits = new byte[rawImage.length * 4]; // That's where the RGBA
// array
// goes.
int i;
for (i = 0; i < rawImage.length; i++) {
Bits[i * 4] = Bits[i * 4 + 1] = Bits[i * 4 + 2] = rawImage[i];
// Invert the source bits
Bits[i * 4 + 3] = -1;// 0xff, that's the alpha.
}
// Now put these nice RGBA pixels into a Bitmap object
Bitmap bm = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888);
bm.copyPixelsFromBuffer(ByteBuffer.wrap(Bits));
return bm;
}
It seems to be fine, but I'm not sure of byte array, how it converts to byte array again based on above format.
Kindly help me to make the below method perfect based on above bitmap method
public byte[] getByteArray(Bitmap bmp) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bmp.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] flippedImageByteArray = stream.toByteArray();
return flippedImageByteArray;
}