绘制验证码

来源:互联网 发布:手机淘宝开店一件代发 编辑:程序博客网 时间:2024/05/20 11:22
绘制验证码:/**     * 绘制图片验证码     *      * @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();    } 





原创粉丝点击