绘制验证码

绘制验证码:
/**
     * 绘制图片验证码
     * 
     * @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();

    } 






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值