You need the Acme graphics library.  There are two ways to do it, either generate the picture and
stream it out as type "image/gif" or create a file on the fly and return an img tag to it. 
 
The Library is available at: http://www.acme.com/
 
Try this just to return the image.  However I think that generating a file is more efficient.
 
void DisplayGraph(HttpServletResponse res,)
throws IOException{
    Frame frame = null;
    Graphics g = null;
 int Scale=1;
 System.out.println("Entering Display");
 ServletOutputStream out = res.getOutputStream();  // binary output!
     try{
       frame = new Frame();
        frame.addNotify();
   Image image = frame.createImage(400, 60);
        g = image.getGraphics();
       g.setFont(new Font("Serif", Font.PLAIN, 12));
        g.setColor(Color.black);
        g.fillRect(0,0,400,60);
        g.setColor(Color.white);
        g.drawString("Some text Say ",10, 15}
 
 System.out.println("Setting Content");      
      res.setContentType("image/gif");
 
            GifEncoder encoder = new GifEncoder(image, out);
    encoder.encode();
     }
     finally {
 System.out.println("Cleaning up");
        // Clean up resources
        if (g != null) g.dispose();
        if (frame != null) frame.removeNotify();
 System.out.println("Finished all drawing");
     }
   
 }
----- Original Message -----
From: Boon Huat
Sent: Friday, February 25, 2000 12:22 AM
Subject: Generating image file ?

Hi all,
 
Does anybody know how to generate a simple image file(eg a graph or chart which is dynamic) from a servlet and output this to the client.
   
Thanks in advance.....
 
Regards
Boon Huat
 
 

Reply via email to