The following code is successfully tested and can be directly copied to jsp (preferred for SUN Enterprise applications ).
<% @ Page import = "java. awt. *" %>
<% @ Page import = "java. awt. image. *" %>
<% @ Page import = "com.sun.image.codec.jpeg. *" %>
<% @ Page import = "java. util. *" %>
<%
// Test by liboy
Int width = 400;
Int height = 400;
BufferedImage image = new BufferedImage (width, height, BufferedImage. TYPE_INT_RGB );
Graphics g = image. getGraphics ();
// Graphics2d g2d = image. createGraphics ();
G. setColor (Color. white );
G. fillRect (0, 0, width, height );
G. setColor (Color. black );
G. drawRect (0, 0, width-1, height-1 );
// 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 ();
Response. reset ();
Response. setContentType ("image/jpeg ");
ServletOutputStream sos = response. getOutputStream ();
Required imageencoder encoder = required codec. createJPEGEncoder (sos );
Encoder. encode (image );
%>
OICQ: 86804