You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by mh...@lwplus.de on 2002/07/05 15:05:02 UTC

Displaying a dynamically created Image.

How do I display a dynamically created Image with struts 
without saving it to my local harddisc and link the image on it?
thanks matthias

----------------------------------------------------------------------------
----------------
Hanel Matthias
Fachinformatiker (Anwendungsentwicklung) in Ausbildung
Logistik World GmbH	Fon:	+49-841-9014-300
Marie-Curie-Strasse 6	Fax:	+49-841-9014-302 
D- 85055 Ingolstadt    	mailto:mhanel@lwplus.de
----------------------------------------------------------------------------
----------------


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Displaying a dynamically created Image.

Posted by Graham Lounder <lo...@caris.com>.
You can read in any file and encode it to jpeg and send it as a response.
Look up the Java Advanced Imaging API to find the JPEG Encoder/Decoder.  You
will also have to set your content type to "image/jpeg".  Here is a sample
function I use to send my generated map image to the client.

    private void sendImage(HttpServletResponse response, BufferedImage bi) {
        try {
            ServletOutputStream out = response.getOutputStream();
            JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
            encoder.encode(bi);
        } catch (IOException ioe) {
            servlet.log("DrawMapAction: IO Exception encoding JPEG to
ServletOutputStream.", ioe);
        }
    }

Then in my html, I make an image tag which points to my struts action such
as

<html:img page="/secure/map/draw.do?ForceRefresh=<%= (new
java.util.Date()).getTime() %>" border="0"/>

The force refresh is to make sure the client browser doesn't cache the
image.

http://java.sun.com/products/java-media/jai/

Hope this helps,
Graham



-----Original Message-----
From: mhanel@lwplus.de [mailto:mhanel@lwplus.de]
Sent: Friday, July 05, 2002 10:05 AM
To: struts-user@jakarta.apache.org
Subject: Displaying a dynamically created Image.



How do I display a dynamically created Image with struts
without saving it to my local harddisc and link the image on it?
thanks matthias

----------------------------------------------------------------------------
----------------
Hanel Matthias
Fachinformatiker (Anwendungsentwicklung) in Ausbildung
Logistik World GmbH	Fon:	+49-841-9014-300
Marie-Curie-Strasse 6	Fax:	+49-841-9014-302
D- 85055 Ingolstadt    	mailto:mhanel@lwplus.de
----------------------------------------------------------------------------
----------------


--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>