Click here to Skip to main content
14,635,966 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have blob data in oracle database i have converted it to byte array.

Now i need to pass this byte array to a function which accepts only Image object.

I want to know how to convert the byte array to Image.

This is the code that I'm using for conversion right now.

Blob temp;
Image[] tempImg=new Image[1];
temp = rs.getBlob("FACE");
nt blobLength = (int) temp.length();
byte[] blobbytes = temp.getBytes(1, blobLength);
tempImg[0] = new ImageIcon(blobbytes).getImage();

getBlob is the function to get the blob data form the database.

any help will be appreciated.
Thanks in advance.
Updated 6-Nov-12 19:24pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You should do it like this:

How To Convert Byte[] To BufferedImage In Java[^]. BufferedImage is a subtype of Image.
Manish_Mohan 7-Nov-12 5:48am
I am the using the same code.

but i'm getting the buffered image as null.
TorstenH. 7-Nov-12 5:50am
you might not be able to write on the HDD. Check the user rights of the OS.
You should use a temporary folder to write the file if that is possible.
Manish_Mohan 7-Nov-12 5:54am
I tried all that.

i kept an "if" condition that the file will only be written in the HDD if the "bImageFromConvert" in not null.
but it is coming out to be null.

here is the code :

temp = rs.getBytes("FACE");

if (temp != null) {
InputStream in = new ByteArrayInputStream(temp);
BufferedImage bImageFromConvert =;
if (bImageFromConvert != null) {
ImageIO.write(bImageFromConvert, "jpg", new File(

JOptionPane.showMessageDialog(null, "image");
JOptionPane.showMessageDialog(null, "bImageFromConvert is null");

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100