<%@ 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);
g.dispose();
// Send back image
ServletOutputStream sos = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(sos);
encoder.encode(image);
%>
jsp画动态图玩
最新推荐文章于 2022-01-14 11:52:48 发布
本文介绍了一个使用Java生成随机几何图案的方法。通过设定画布尺寸、背景颜色及随机生成的五边形位置,最终将图案输出为JPEG格式的图片。此教程适合希望了解如何在服务器端动态生成图像的开发者。

1016

被折叠的 条评论
为什么被折叠?



