<% @ Page contentType = "image/jpeg"
Import = "java. awt. *, java. awt. image .*,
Com.sun.image.codec.jpeg. *, java. util .*"
%>
<%
// Create image
Int width = 200, height = 200;
BufferedImage image = new BufferedImage (width,
Height, BufferedImage. TYPE_INT_RGB );
// Get drawing context (Code Lab)
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 <5; 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 ();
Required imageencoder encoder =
Required codec. createJPEGEncoder (sos );
Encoder. encode (image );
%> (Code Lab)