图片效果:
<!--
自我补充篇之java随机验证码的生成
Goal:利用java代码生成随机验证码的图片(今天终于想起写这个了)!
-->
我的验证码的优势:每个字母的颜色不同~,大小写字母数字混合,干扰线无规律,颜色也不同!
缺点:有点传统
代码:
public static void main(String[] lovingshu){
//Create a image in RAM
BufferedImage bufImage=new BufferedImage(100,30,BufferedImage.TYPE_3BYTE_BGR);
//get the paint of the image in RAM
Graphics gra=bufImage.getGraphics();
//seed of random
Random ran=new Random();
//fill the background
gra.setColor(Color.WHITE);
gra.fillRect(0, 0, 100, 30);
//the String of code
String vliCode="";
//set font
gra.setFont(new Font("微软雅黑",Font.ITALIC,20));
//start to draw the letter
while(vliCode