package com.accp.acg;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import javax.imageio.ImageIO;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
public class test extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
BufferedImage b = new BufferedImage(200, 100,
BufferedImage.TYPE_INT_RGB);
Graphics g = b.getGraphics();
g.setColor(Color.white);
g.fillRect(0, 0, 200, 100);
g.setColor(Color.red);
g.drawRect(5, 5, 190, 90);
Random rnd = new Random();
int type = 0;
// String n = "";
int n=0;
String line = "";
for (int i = 0; i < 5; i++) {
type = rnd.nextInt(3);
switch (type) {
case 0:
n = rnd.nextInt(10);
break;
case 1:
// char s=(char) (rnd.nextInt('z' - 'a' + 1) + 'a');
// n += s;
n=rnd.nextInt('z' - 'a' + 1) + 'a';
break;
case 2:
// s=(char) (rnd.nextInt('Z' - 'A' + 1) + 'A');
// n += s;
n=rnd.nextInt('Z' - 'A' + 1) + 'A';
break;
}
if (type == 0) {
line += n;
} else {
line += (char)n;
}
}
HttpSession session = request.getSession();
session.setAttribute("line", line);
g.setFont(new Font("行楷", Font.ITALIC, 55));
g.setColor(Color.black);
g.drawString(line, 10, 70);
for(int i=0;i<10;i++)
{
int m=rnd.nextInt(190-5+1)+5;
int l=rnd.nextInt(190-5+1)+5;
g.setColor(Color.cyan);
g.drawLine(m, l, l, m);
g.drawOval(m, l, l, m);
}
response.reset();
response.setContentType("image/jpeg");
OutputStream os = response.getOutputStream();
ImageIO.write(b, "jpg", os);
os.close();
}
}
阅读(363) | 评论(0) | 转发(0) |