Solved

Hex String to Image file

Posted on 2006-11-01
5
543 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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 learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

707 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now