Hex String to Image file

Right now I use Oracles XDK to query the database and return an XML string.  The XML contains an element which is an image(comes from a Blob).  The data is in Hex format.  Is there a way to take a HEX string and convert it back to a JPEG?  I have tried converting the HEX to binary but its too big and will take too long.  Any help would be greatly appreciated.
LVL 1
bigboy1122Asked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
// you can load it as an image using:

Image image = ImageIO.read(new ByteArrayInputStream(new BigInteger(hexString, 16).toByteArray()));

// or save it directly to a file using:

OutputStream out = new BufferedOutputStream(new FileOutputStream("image.jpg"));
out.write(new BigInteger(hexString, 16).toByteArray());
out.close();
0
 
CEHJCommented:
byte[] imageBytes = new BigInteger(hexString).toByteArray();
// Create an image with the array
0
 
CEHJCommented:
Sorry

byte[] imageBytes = new BigInteger(hexString, 16).toByteArray();
0
 
bigboy1122Author Commented:
Thanks guys. Just what I was looking for.
0
 
CEHJCommented:
Not sure why i received no credit for the answer accepted, since i provided most of it ...
0
All Courses

From novice to tech pro — start learning today.