Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to display image on browser from byte array

 
kumar sivaramakrishnan
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using an api in a web app to return a byte array of an image stored in a database. I have tried dumping the byte array into the response but the browser does not display it. Believe the image is a tiff so I also tried downloading the tiff browser plugin. Still does not work.

What is the best way to do this?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most browsers don't display tiff without the aid of plugins.
You might want to test with the browsers you plan to support by trying to serve up a static tiff file using a plain old <img /> tag before going too far with this..


In our CodeBarn, in the servlets section, there is a sample app, packaged in a war file that streams images to browsers. Look for SimpleStream. In that app, the images are read from disk using context.getResourceAsStream. You'll need to modify it to serve up your byte array or, (if your library can serve one) a stream. It should be enough to get you going though.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic