[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Hex String to Image file

Posted on 2006-11-01
5
Medium Priority
?
554 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month18 days, 1 hour left to enroll

830 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