Creating image from byte array

Hi,

I am storing an image as BLOB into database and then reading it as byte array and trying to convert it to an image ( get back the original image). I am using the following code. But when I print the image object, it prints null.

BufferedImage image = ImageIO.read( new ByteArrayInputStream( imageBuf ) );

Can I not store an image simply as a byte array and then get the image back from that byte array?

[431 byte] By [maitya] at [2007-11-27 5:41:53]
# 1
But how did you *write* the data? With ImageIO.write?
Hippolytea at 2007-7-12 15:19:54 > top of Java-index,Java Essentials,Java Programming...
# 2
And make sure that you have an ImageReader that can reconstruct the image.
ChuckBinga at 2007-7-12 15:19:54 > top of Java-index,Java Essentials,Java Programming...
# 3

I would first test it without the database, just:

image --> byte[] --> image

to see if your encode/decode sequence works.

Only then add the database to the mix:

image --> byte[] --> database --> byte[] --> image

And in this case, you should verify that the two arrays are the

same length and byte-by-byte identical.

Hippolytea at 2007-7-12 15:19:54 > top of Java-index,Java Essentials,Java Programming...