• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert binary data into jpg

 
Nitin Agarwal
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Pie
Posts: 20971
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic