Hi all,
I have an array of bytes that I'm trying to convert to a BufferedImage so I can save the image as a file. Currently, I am converting the array of bytes to an Image, but I would prefer it to be a BufferedImage so it is easier to work with. I am unsure how to do this though, or even if it can be done.
I have read the API docs for BufferedImage and javax.imageio, Raster, and the sort, but I am unsure where to start. Here is what I currently have:
Image image;
byte[] in = imAq.acquireImage();
image = Toolkit.getDefaultToolkit().createImage(in);
File f = new File("/u/dgresh/Pic.jpg");
ImageIO.write(image, "jpeg", f); //This does not work because image is not a BufferedImage
I've read somewhere that it is not possible to convert a BufferedImage to a byte array (I googled for "convert byte array to BufferedImage" and found the converse) because of serialization or something. Therefore, if I cannot convert a byte array to a BufferedImage, is there another way I could do this?
Basically the end result of what I want to do is encode the byte array into an image format such as GIF; it does not necessarily have to be saved to the local filesystem (I am attempting to do this now for testing purposes).
Thanks,
Dan