当前位置: 首页 > 图文教程 > 网络编程 > JSP > JSP技巧:发送动态图像(3)

JSP
JSP由浅入深(8)
JSP由浅入深(5-2)
JSP由浅入深(5-1)
[学习笔记]**编写"纯HTML"jsp应用--学会使用JSTL**
小议<scriptsrc=aaa.js></script>
[学习笔记]**编写"纯HTML"jsp应用--学会使用
HTML和javascript结合的例子
讲一讲setproperty(name="*")的用法或介绍相关资料
关于Servlet、Jsp中的多国语言显示(续)<太长了>
JSP语法(8)——<jsp:forward>
JSP语法(9)——<jsp:getProperty>
JSP语法(10)——<jsp:include>
JSP语法(12)——<jsp:useBean>
JSP语法(11)——<jsp:plugin>
关于认证的一些介绍
JSP语法(13)——<jsp:useBean>
java反射技术(一)
JAVA反射技术(二)
jsp连接mysql数据库大全
JSP入门教程(2)

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-09-04   浏览: 60 ::
收藏到网摘: n/a

  <%@ 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);
  %> (代码实验室)