Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Servlet Dynamic Image Generation 1

Status
Not open for further replies.

moweis

Programmer
Dec 13, 2001
2
US
Hi,

I have a question as to how I can send an already existing image (i.e. ".jpg", ".gif") as the response of an HttpServletRequest.

I was able to send an image back as a response when I generate the image dynamically. That is, I create a JFrame object, paint it, then convert to JPeg with the JPeg encoder, then send it back on the Output stream of the response object.

What I want to do now is to be able to load a gif/jpeg image, draw on it, and then send the combination back on the Output stream as an image (preferably gif, but will accept anything for now).

I would appreciate any help in this matter. I would really prefer a end-to-end example, as supposed to some code tid-bits, because i'm still not completely familiar with all the different paint/paintComponents/.... methods (as far as who to call, and when, and why).

Thanks for any help
Marwan
 
response.setContentType("image/gif");
InputStream in = new FileInputStream("my.gif");
OutputStream out = response.getOutputStream();
int c;
while ((c = in.read()) != -1)
out.write(c);
in.close();
out.close();

This will send your image file back to the browser as content type 'image/gif' which means that it will render it as an image.

You can (and I have) use this technique to create an image server for many image types.
 
Thanks for the response. I will try that.

As far as drawing (plotting points) on the jpeg/gif that I load, is that possible?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top