package com.wensi.util;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Random;
import javax.imageio.ImageIO;
//驗證碼生成
public class CheckDemo {
public static void main(String[] args) throws IOException {
int width = 150;
int height = 35;
BufferedImage image = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
g.setColor(Color.GRAY);
g.fillRect(1, 1, width-2, height-2);
g.setColor(Color.BLUE);
g.drawRect(0, 0, width, height);
g.setColor(Color.red);
Random r = new Random();
for(int i=0;i<50;i++){
g.drawLine(r.nextInt(width), r.nextInt(height),r.nextInt(width), r.nextInt(height));
}
Font f = new Font("黑體",Font.BOLD,30);
g.setFont(f);
int x = 30;
g.setColor(Color.BLUE);
for(int i =0;i<4;i++){
g.drawString(String.valueOf(r.nextInt(10)),x, 25);
x+=30;
}
File file = new File("E:/photo/tutu.jpg");
ImageIO.write(image, "jpg", file);
}
}