Originally posted by Thomas Paul: You can't. An AWT Image can only be displayed in an Applet or a Frame.
Bzzzt. Images work just as well for drawing offline images. Let's start at the client -- you incorporate an image using an <IMG> tag. Point this tag at a servlet. This servlet will generate the binary stream that represents the image as output. The best thing is to communicate all the parameters necessary to generate the image to your servlet, rather than pre-generate the image and leaving it to consume resources on your server until the client requests it. These parameters can sit either in image URL parameters or in your session context. The servlet then generates the image. Make sure you have a javax.awt.image.BufferedImage. Use the graphics context or whatever to draw on it what you want. The next step is to convert the image to something the browser understands. Sun's JDK only ships with a JPEG encoder afaik (com.sun.image.codec.jpeg.JPEGCodec.createJPEGEncoder()). This encoder takes your BufferedImage, encodes it and writes it to an OutputStream. The response.getOutputStream() will do fine. Be sure to set your response headers before writing the image especially response.setContentType(). - Peter
Joined: May 05, 2000
of course you can do it! You can do it in Perl so why shouldn't you be able to do it in Java? Here is a sample program:
Here's the HTML: <HTML> <HEAD> <TITLE>Image Display HTML</TITLE> </HEAD> <BODY bgcolor="black"> <br> <br> <br> <center><img src="/servlet/ImageDisplayer"></center> </BODY> </HTML> [This message has been edited by Thomas Paul (edited February 16, 2001).]
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: java.awt.Image to a HTML file via a servlet