[小技巧]快速生成验证码
2017-09-03 00:00
337 查看
摘要: 嗯,有人问我验证码生成是不是要在web上运行,我说验证码生成跟java web没半毛钱关系。他不相信,所以我就写了一个列子。
有没有理由自己造轮子,因为有更好的。
直接上测试代码。
就这样了。
有没有理由自己造轮子,因为有更好的。
<dependency> <groupId>com.github.penggle</groupId> <artifactId>kaptcha</artifactId> <version>2.3.2</version> </dependency>
直接上测试代码。
public static void main(String[] args) { Properties properties = new Properties(); properties.setProperty("kaptcha.border", "yes"); properties.setProperty("kaptcha.border.color", "105,179,90"); properties.setProperty("kaptcha.textproducer.font.color", "blue"); properties.setProperty("kaptcha.image.width", "125"); properties.setProperty("kaptcha.image.height", "45"); properties.setProperty("kaptcha.textproducer.font.size", "45"); properties.setProperty("kaptcha.session.key", "code"); properties.setProperty("kaptcha.textproducer.char.length", "4"); properties.setProperty("kaptcha.textproducer.font.names", "宋体,楷体,微软雅黑"); Config config = new Config(properties); DefaultKaptcha defaultKaptcha = new DefaultKaptcha(); defaultKaptcha.setConfig(config); String capText = defaultKaptcha.createText(); //验证码 System.out.println(capText); BufferedImage bi = defaultKaptcha.createImage(capText); File file = new File("D:\\temp\\image.jpg"); try { ImageIO.write(bi, "jpg", file); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
就这样了。
相关文章推荐
- Android studio使用小技巧之 快速生成onClick()点击方法
- Cage 是一个 Java 实现的验证码图片生成库,快速、小型和简单。
- python快速生成验证码(密码)
- Javaweb中快速生成验证码Captcha
- VS2015使用小技巧 使用ctrl+r,ctrl+e快捷键为字段快速生成属性
- Python 小技巧:快速生成初始化二维数组
- 快速生成数据库列枚举的小技巧
- iOS防止用户恶意点击场景分析、防止用户恶意点击方法之本地动态验证码生成
- java图形验证码生成工具类
- 生成验证码
- 快速生成网站
- php基础之gd图像生成、缩放、logo水印和简单验证码实现
- .NET使用一般处理程序生成验证码
- 生成验证码
- php生成随机验证码
- 生成随即验证码图片
- java 生成验证码
- Java生成图片验证码(有点仿QQ验证码的意思)
- .NET使用一般处理程序生成验证码(转)
- 随机生成验证码制作【深海原创】