I have a byte array which size is 640*480*3 and its byte order is r,g,b. I'm trying to convert it into Image. The following code doesn't work:
BufferedImage img = ImageIO.read(new ByteArrayInputStream(data));
with the excepton
Exception in thread "main" java.lang.IllegalArgumentException: image == null!
at javax.imageio.ImageTypeSpecifier.createFromRenderedImage(ImageTypeSpecifier.java:925)
at javax.imageio.ImageIO.getWriter(ImageIO.java:1591)
at javax.imageio.ImageIO.write(ImageIO.java:1520)
I also tried this code:
ImageIcon imageIcon = new ImageIcon(data);
Image img = imageIcon.getImage();
BufferedImage bi = new BufferedImage(img.getWidth(null),img.getHeight(null),BufferedImage.TYPE_3BYTE_BGR); //Exception
but unsuccessfully:
Exception in thread "main" java.lang.IllegalArgumentException: Width (-1) and height (-1) must be > 0
How can I receive the Image from this array?