• 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

How do I get a byte-array to display the image in a browser ???

 
Ranch Hand
Posts: 277
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I have a .gif image stored in a byte array :
public byte[] picture;
I really do not want to write to a file first, and then use getImage() method to display the picture because it is an i/o overhead.
Are there any other ways of doing this ???
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Basically you want to have the image data served by a servlet from the byte array instead of the web server from a file. You have to arrange that the URL in the <img> tag points to a servlet that has the byte array. You have to set the response content-type to "image/gif" and the content-length to the byte[].length. See the HttpServletResponse API.
You MUST get an output stream instead of a writer so the bytes will go out unaltered. Then just write the byte array and close the stream.
This is a common item in many servlet books and you can find plenty of related discussions in older threads here.
Bill
 
Think of how stupid the average person is. And how half of them are stupider than that. But who reads this tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic