编写算数验证码绘制方法
这个方法比上一个高级一点,我们还用了干扰线。
public static String drawImageVerificate(HttpServletResponse response){
//定义验证码的宽度和高度
int width = 100,height = 30;
//在内存中创建图片
BufferedImage image = new BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
//创建图片的上下文
Graphics2D g = image.createGraphics();
//产生随机对象,此随机对象主要用于算术表达式的数字
Random random = new Random();
//设置背景
g.setColor(getRandomColor(240,250));
//设置字体
g.setFont(new Font("微软雅黑", Font.PLAIN,22));
//开始绘制
g.fillRect(0,0,width,height);
//干扰线的绘制,绘制线条到图片中
g.setColor(getRandomColor(180,230));
for(int i=0;i<10;i++){
int x = random.nextInt(width);
int y = random.nextInt(height);
int x1 = random.nextInt(60);
int y1 = random.n