验证码识别技术
来源:百度知道 编辑:UC知道 时间:2024/06/19 04:09:55
public void service(HttpServletRequest req, HttpServletResponse res)
throws IOException
{
// 验证码图片的宽度。
int width = 70;
//验证码图片的高度。
int height=36;
BufferedImage buffImg=new BufferedImage(width,height,
BufferedImage.TYPE_INT_RGB);
Graphics2D g=buffImg.createGraphics();
//创建一个随机数生成器类。
Random random=new Random();
// 设定图像背景色(因为是做背景,所以偏淡)
g.setColor(getRandColor(180, 250));
g.fillRect(0,0,width,height);
//创建字体,字体的大小应该根据图片的高度来定。
Font font=new Font("Times New Roman",Font.PLAIN,28);
//设置字体。
g.setFont(font);
//画边框。
g.setColor(Color.BLACK);
g.drawRect(0,0,width-1,height-1);
// 随机产生160条干扰线,使图象中的认证码不易被其它程序探测到。
g.setColor(Color.GRAY);
for (int i=0;i<50;i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl =