当前位置:系统之家 > 技术开发教程 > 详细页面

JSP技巧:发送动态图像(3)

JSP技巧:发送动态图像(3)

更新时间:2022-05-22 文章作者:未知 信息来源:网络 阅读次数:

  <%@ 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  (代码实验室)
  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();
  JPEGImageEncoder encoder =
  JPEGCodec.createJPEGEncoder(sos);
  encoder.encode(image);
  %> (代码实验室)



温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行