V> Does anybody have a good article/source as how to create dynamic
V> images/graphs using servlets.

try this example

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.image.codec.jpeg.*;
import java.util.*;

public class MakeImage extends HttpServlet {

   public void doGet(
       HttpServletRequest request,
       HttpServletResponse response)
         throws ServletException, IOException {

     response.setContentType("image/jpeg");

     // Create image
     int width=200, height=200;
     BufferedImage image = new BufferedImage(
       width, height, BufferedImage.TYPE_INT_RGB);

     // Get drawing context
     Graphics g = image.getGraphics();

     // Fill background
     g.setColor(Color.white);
     g.fillRect(0, 0, width, height);

     // Create random polygon
     Polygon poly = new Polygon();
     Random random = new Random();
     for (int i=0; i < 20; i++) {
       poly.addPoint(random.nextInt(width),
         random.nextInt(height));
     }

     // Fill polygon
     g.setColor(Color.cyan);
     g.fillPolygon(poly);

     // Dispose context
     g.dispose();

     // Send back image
     ServletOutputStream sos =
       response.getOutputStream();
     JPEGImageEncoder encoder =
       JPEGCodec.createJPEGEncoder(sos);
     encoder.encode(image);

   }
}

Delivering Dynamic Images from JavaServer PagesTM (JSPTM) Technology.
http://java.sun.com/jdc/JDCTechTips/2001/tt0821.html

--
Best regards,
Yuriy

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to