?
Solved

Hex String to Image file

Posted on 2006-11-01
5
Medium Priority
?
550 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month8 days, 21 hours left to enroll

764 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