Draw pictures directly with JSP and output to IE

xiaoxiao2021-03-06  54

The following code can be successfully processed directly to the JSP directly.

<% @ 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 ) {polyxtint (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 (); JPEGIMAGEENCODER Encoder = JPEGCODEC.CREATEJPEGENCODER (SOS); Encoder.Encode (Image);

%>

OICQ: 86804

转载请注明原文地址:https://www.9cbs.com/read-115440.html

New Post(0)