Search code examples
javaimagejpegbmpjavax.imageio

How to convert JPG data stored in a Byte array to BGR data in java


Possible Duplicate:
Getting pixel data from an image using java

I was already browsing the web for quite some time, but didn't find any suitable answer, so I would be very happy if someone here could help me :)

I have a Byte array which is filled with image data encoded as JPEG. Now I would like to know how to convert the data to the corresponding BGR data of the image and store it in a byte array as well.

Thank you very much in advance, your help is really appreciated!


Solution

  • You could try this:

        ByteArrayInputStream input = new ByteArrayInputStream(byteArray);
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        BufferedImage image = ImageIO.read(input); 
        ImageIO.write(image, "bmp", output);  
        byte[] outputBytes = output.toByteArray();