wood burning stoves*
The moose likes Swing / AWT / SWT and the fly likes convert binary data into jpg Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "convert binary data into jpg " Watch "convert binary data into jpg " New topic
Author

convert binary data into jpg

Nitin Agarwal
Greenhorn

Joined: Dec 15, 2005
Posts: 9
Hi,

how to convert binary data into jpg image through java.
I have xml file which contain <Binary> element in which binary data of image is fill and through java swing we have to read it and display image in JFrame.

Thanks
Nitin
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
I don't know what form the data has when you get it out of your XML document,
but you can use this method of javax.imageio.ImageIO:

public static BufferedImage read(InputStream input) throws IOExeption

If the XML API gives you a byte[] instead of an InputStream, there's
always ByteArrayInputStream.


There is no emoticon for what I am feeling!
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

However XML is a text format that does not permit arbitrary binary data, so if it contains bytes to make a JPG then those bytes must have been encoded in some way. You will have to decode them in the corresponding way, whatever that is. It is common to use Base64 encoding to put binary data into XML but that does not mean your binary data was encoded that way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert binary data into jpg