EasyCaptcha icon indicating copy to clipboard operation
EasyCaptcha copied to clipboard

请问如何设置字体颜色?

Open Apparition2018 opened this issue 6 years ago • 4 comments

Apparition2018 avatar Dec 20 '19 01:12 Apparition2018

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

liufeikl2008 avatar Dec 25 '19 01:12 liufeikl2008

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

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

Rick691 avatar Feb 21 '20 05:02 Rick691

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

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

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

vsouild avatar May 05 '20 19:05 vsouild

继承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);
}

LSL1618 avatar Apr 26 '24 06:04 LSL1618