private int width = 60;
// 定义验证码图片的高度。
private int height = 20;
// 定义验证码字符个数,此处设置为5位
private int codeNum = 5;
Color getRandColor(int ff,int cc){
//给定范围获得随机颜色
Random random = new Random();
if(ff>255) ff=255;
if(cc>255) cc=255;
int r=ff+random.nextInt(cc-ff);
int g=ff+random.nextInt(cc-ff);
int b=ff+random.nextInt(cc-ff);
return new Color(r,g,b);
}
char[] codes = { ‘0’, ‘1’, ‘2’, ‘3’, ‘4’, ‘5’, ‘6’, ‘7’, ‘8’, ‘9’, ‘A’,
‘B’, ‘C’, ‘D’, ‘E’, ‘F’, ‘G’, ‘H’, ‘I’, ‘J’, ‘K’, ‘L’, ‘M’, ‘N’,
‘O’, ‘P’, ‘Q’, ‘R’, ‘S’, ‘T’, ‘U’, ‘V’, ‘W’, ‘X’, ‘Y’, ‘Z’, };
/**
- 对验证图片属性进行初始化
*/
public void init() throws ServletException {
// 从部署文件web.xml中获取程序初始化信息,图片宽度跟高度,字符个数信息
// 获取初始化字符个数
String strCodeNums = this.getInitParameter(“codeNum”);
// 获取验证码图片宽度参数
String strW = this.getInitParameter(“w”);
// 获取验证码图片高度参数
String strH = this.getInitParameter(“h”);
// 将配置的字符串信息转换成数值类型数字
try {
if (strH != null && strH.length() != 0) {
height = Integer.parseInt(strH);
}
if (strW != null && strW.length() != 0) {
width = Integer.parseInt(strW);
}
if (strCodeNums != null && strCodeNums.length() != 0) {
codeNum = Integer.parseInt(strCodeNums);
}
} catch (NumberFormatException e) {
}
x = width / (codeNum + 1);
fontHeight = height - 2;
codeY = height - 4;
}
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, java.io.IOException {
// 定义验证码图像的缓冲流
BufferedImage buffImg = new BufferedImage(width, height,
BufferedImage.TYPE_INT_RGB);
// 产生图形上下文
Graphics2D g = buffImg.createGraphics();
// 创建随机数产生函数
Random random = new Random();
// 将验证码图像背景填充为白色
g.setColor(getRandColor(210, 260));
g.fillRect(0, 0, width, height);
// 创建字体格式,字体的大小则根据验证码图片的高度来设定。
Font font = new Font(“Fixedsys”, Font.PLAIN, fontHeight);
// 设置字体。
g.setFont(font);
// 为验证码图片画边框,为一个像素。
g.setColor(Color.BLACK);
g.drawRect(0, 0, width - 1, height - 1);
// 随机生产120跳图片干扰线条,使验证码图片中的字符不被轻易识别
g.setColor(getRandColor(110, 240));
for (int i = 0; i < 120; i++) {
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x, y, x + xl, y + yl);
}
// randomCode保存随机产生的验证码
StringBuffer randomCode = new StringBuffer();
// 定义颜色三素
int red = 0, green = 0, blue = 0;
自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。
深知大多数同学面临毕业设计项目选题时,很多人都会感到无从下手,尤其是对于计算机专业的学生来说,选择一个合适的题目尤为重要。因为毕业设计不仅是我们在大学四年学习的一个总结,更是展示自己能力的重要机会。
因此收集整理了一份《2024年计算机毕业设计项目大全》,初衷也很简单,就是希望能够帮助提高效率,同时减轻大家的负担。
既有Java、Web、PHP、也有C、小程序、Python等项目供你选择,真正体系化!
由于项目比较多,这里只是将部分目录截图出来,每个节点里面都包含素材文档、项目源码、讲解视频
如果你觉得这些内容对你有帮助,可以添加VX:vip1024c (备注项目大全获取)
6275)]
既有Java、Web、PHP、也有C、小程序、Python等项目供你选择,真正体系化!
由于项目比较多,这里只是将部分目录截图出来,每个节点里面都包含素材文档、项目源码、讲解视频
如果你觉得这些内容对你有帮助,可以添加VX:vip1024c (备注项目大全获取)
[外链图片转存中…(img-WMq57IKr-1712521466275)]