Solved

Hex String to Image file

Posted on 2006-11-01
5
545 Views
Last Modified: 2011-10-03
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.
0
Comment
Question by:bigboy1122
  • 3
5 Comments
 
LVL 86

Expert Comment

by:CEHJ
ID: 17850792
byte[] imageBytes = new BigInteger(hexString).toByteArray();
// Create an image with the array
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17850804
Sorry

byte[] imageBytes = new BigInteger(hexString, 16).toByteArray();
0
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 17853024
// 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
 
LVL 1

Author Comment

by:bigboy1122
ID: 17866198
Thanks guys. Just what I was looking for.
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 17866815
Not sure why i received no credit for the answer accepted, since i provided most of it ...
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question