绘制验证码: /** * 绘制图片验证码 * * @return */ public ConfigurableCaptchaService getCs() { ConfigurableCaptchaService cs = new ConfigurableCaptchaService(); cs.setColorFactory(new SingleColorFactory(new Color(25, 60, 170))); RandomFontFactory r = new RandomFontFactory(); r.setMaxSize(8); r.setRandomStyle(true); List<String> list = new ArrayList<String>(); list.add("Cursive"); r.setFamilies(list); cs.setFontFactory(r); cs.setFilterFactory(new CurvesRippleFilterFactory(cs.getColorFactory())); cs.setWidth(100); cs.setHeight(45); cs.setColorFactory(new SingleColorFactory(new Color(25, 60, 170))); RandomWordFactory t = new RandomWordFactory(); t.setCharacters("0123456789abcdefghijklmnopqrstuvwsyzABCDEFGHIJKLMNOPQRSTUVWSYZ"); t.setCharacters("0123456789"); t.setMaxLength(4); t.setMinLength(4); cs.setWordFactory(t); return cs; } 测试: public static void main(String[] args) throws Exception { ConfigurableCaptchaService cs = new ValicodeServiceImpl().getCs(); // 输出位置 FileOutputStream fileOutputStream = new FileOutputStream("D://1.png"); // 生成验证码 EncoderHelper.getChallangeAndWriteImage(cs, "png", fileOutputStream); fileOutputStream.close(); }
绘制验证码
最新推荐文章于 2022-12-09 21:00:48 发布