0

I have an array of bytes which represents JPEG image. Is there any way to convert it directly to RGB array? What i'm doing now is first create Buffered Image and thet get RGB array from it. Maybe, there is less expensive way to do this?

BufferedImage bufImage = new BufferedImage(640, 480, BufferedImage.TYPE_INT_RGB);
ByteArrayInputStream stream = new ByteArrayInputStream(jpegBytes);
bufImage = ImageIO.read(stream);
int[] ib = bufImage.getRGB(0, 0, bufImage.getWidth(), bufImage.getHeight(), null, 0, bufImage.getWidth());
  • 3
    Possible duplicate: http://stackoverflow.com/a/3211685/3082272 – bobbel Dec 17 '13 at 12:51
  • I don't want to create `BufferredImage` at all, I want to decompress from JPEG byte array to RGB – Aleksey Sergeev Dec 17 '13 at 13:02
  • You can't directly convert a JPEG image byte data array to a RGB data array. Because JPEGs have some compression algorithm. And you'd have to implement your own logic to convert the compressed data array to the real RGB values. So the easiest way is, to use the addressed methods how you can convert it! – bobbel Dec 17 '13 at 13:13
  • Thank you, i should leave it this way. – Aleksey Sergeev Dec 17 '13 at 13:20
  • You don't need to create a `BufferedImage`... `ImageIO.read(..)` will create one for you, and the one you create is just garbage collected... Also, keep in mind that `BufferedImage` isn't some magic super-expensive object, it's a quite thin wrapper around the data array. – Harald K Dec 18 '13 at 08:46

0 Answers0