IDependOn-Set: 1
IDependOn-Set: 119
IDependOn-Set: 199
IDependOn-Set: 2
IDependOn-Set: 204
IDependOn-Set: 205
LastModifiedSecs: 937988589
Parent: 119
SequenceNumber: 4
Title: How do I create an image with a servlet, for example, a graph out of a list of values? 
Part: 0
Author-Set: jon@working-dogs.com
HideAttributions: 1
LastModifiedSecs: 928905713
Type: html
Lines: 20
Servlets allow you to specify the content type of the
        response. This ability let you generate dynamic images simply mapping the &lt;img&gt; tag
        with the proper servlet URL. To do this, you need to generate an off-screen image object
        and send it encoded in your favorite image format. Free GIF image encoders are not
        available due to patent restrictions, while JDK 1.2 contains a JPG image encoder (and few
        others like PNG may be added in the future).<p>To create an off-screen image you could
        follow these guidelines:</p>
        <blockquote>
          <pre>Frame f = new Frame();

f.addNotify() // &lt;-- this creates a &quot;frame peer&quot;, which makes it all work

Image img = f.createImage();
doMyPaintImage(img.getGraphics());

(etc.)</pre>
        </blockquote>
        <p>Note that it apparently needs to be a Frame since Canvas doesn't seem to work. It
        probably just calls for the toplevel window component to do the job. (Thanks to Bjorn
        Sandberg).
EndPart: 0
Part: 1
Author-Set: rbk@ebs.hw.ac.uk
HideAttributions: 1
LastModifiedSecs: 937988588
Type: html
Lines: 1
If you are running on a Unix box, then to create a Frame the Java process needs access to a X server (and the DISPLAY environment variable set). If you do not want the overhead of running an X server, then you can use Xvfb which creates a virtual X server.
EndPart: 1
