ele-admin / EasyCaptcha

Java图形验证码,支持gif、中文、算术等类型,可用于Java Web、JavaSE等项目。

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

请问如何设置字体颜色?

Apparition2018 opened this issue · comments

是的,字体颜色怎么设置,我也遇到的这个问题,求解答,谢谢!验证码颜色跟网站整体效果不搭

是的,字体颜色怎么设置,我也遇到的这个问题,求解答,谢谢!验证码颜色跟网站整体效果不搭

继承 Captcha ,重写graphicsImage(char[] strs, OutputStream out)方法,修改g2d.setColor(Color.BLACK);

是的,字体颜色怎么设置,我也遇到的这个问题,求解答,谢谢!验证码颜色跟网站整体效果不搭

继承 Captcha ,重写graphicsImage(char[] strs, OutputStream out)方法,修改g2d.setColor(Color.BLACK);

不用那么复杂,在实例化验证码对象的时候重写Captcha的color()方法就行,设置返回值为需要的颜色

继承SpecCaptcha类,参考父类并重写color()方法,或者重写out()、graphicsImage()方法,重点在graphicsImage()方法中的这里:

for(int i = 0; i < strs.length; ++i) {
    // 此处设置字体颜色
    g2d.setColor(this.color());
    int fY = this.height - (this.height - (int)fontMetrics.getStringBounds(String.valueOf(strs[i]), g2d).getHeight() >> 1);
    g2d.drawString(String.valueOf(strs[i]), i * fW + fSp + 3, fY - 3);
}