TA的每日心情 | 开心 2021-3-12 23:18 |
---|
签到天数: 2 天 [LV.1]初来乍到
|
<%@ page contentType="image/jpeg" import="java.awt.*,java.awt.image.*,
com.sun.image.codec.jpeg.*,java.util.*" %>
<%
//创建图像
int width=200, height=200;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
// 获取绘图环境的上下文
Graphics g = image.getGraphics();
// 填充背景
g.setColor(Color.white);
g.fillRect(0, 0, width, height);
// 创建一个随机的多边形
Polygon poly = new Polygon();
Random random = new Random();
for (int i=0; i < 5; i++) {
poly.addPoint(random.nextInt(width),
random.nextInt(height));
}
// 填充多边形
g.setColor(Color.blue);
g.fillPolygon(poly);
// Dispose context
g.dispose();
// Send back image
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
//创建JPEGImage图像编码器
encoder.encode(image);
%>
源码下载:http://file.javaxxz.com/2014/10/1/025530375.zip |
|