• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

convert binary data into jpg

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 27235
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic