该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
//禁用缓存
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
int height = 20;
int width = 60;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
Graphics g = image.getGraphics();
g.setColor(getRandomColor(200, 250));
g.fillRect(0, 0,width, height);
g.setFont(new Font("Times New Roman", Font.PLAIN, 18));
g.setColor(getRandomColor(200, 255));
Random random = new Random();
for(int i= 0;i<150;i++){//150条干扰线
int x = random.nextInt(width);
int y = random.nextInt(height);
int x1 = random.nextInt(12);
int y1 = random.nextInt(12);
g.drawLine(x, y, x+x1, y+y1);
}
String codeStr = "";
for(int i= 0;i<4;i++){
String strNum = String.valueOf(random.nextInt(10));
codeStr = codeStr+strNum;
g.setColor(new Color(5+random.nextInt(120),5+random.nextInt(120),5+random.nextInt(120)));
g.drawString(strNum, 13*i+6, 16);
}
g.dispose();
ImageIO.write(image, "JPEG", response.getOutputStream());
response.getOutputStream().flush();
response.getOutputStream().close();