增加中文验证码功能
This commit is contained in:
@@ -69,23 +69,39 @@ public class ChineseGifCaptcha extends ChineseCaptchaAbstract {
|
||||
g2d.setColor(Color.WHITE); // 填充背景颜色
|
||||
g2d.fillRect(0, 0, width, height);
|
||||
AlphaComposite ac3;
|
||||
int h = height - ((height - font.getSize()) >> 1);
|
||||
int w = width / len;
|
||||
g2d.setFont(font);
|
||||
g2d.setColor(fontcolor);
|
||||
// 抗锯齿
|
||||
g2d.setColor(fontcolor);
|
||||
g2d.setFont(font);
|
||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
||||
// 画验证码
|
||||
int hp = (height - font.getSize()) >> 1;
|
||||
int h = height - hp;
|
||||
int w = width / strs.length;
|
||||
int sp = (w - font.getSize()) / 2;
|
||||
for (int i = 0; i < len; i++) {
|
||||
ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, getAlpha(flag, i));
|
||||
g2d.setComposite(ac3);
|
||||
int x = i * w + num(2, 6);
|
||||
g2d.drawString(String.valueOf(strs[i]), x, h - num(2, 6));
|
||||
// 计算坐标
|
||||
int x = i * w + sp + num(-Math.abs(sp), Math.abs(sp));
|
||||
int y = h + num(-3, 3);
|
||||
if (x < 0) {
|
||||
x = 0;
|
||||
}
|
||||
if (x + font.getSize() > width) {
|
||||
x = width - font.getSize();
|
||||
}
|
||||
if (y > height) {
|
||||
y = height;
|
||||
}
|
||||
if (y - font.getSize() < 0) {
|
||||
y = font.getSize();
|
||||
}
|
||||
g2d.drawString(String.valueOf(strs[i]), x, y);
|
||||
}
|
||||
// 随机画干扰线
|
||||
g2d.setStroke(new BasicStroke(1.2f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
|
||||
for (int i = 0; i < 5; i++) {
|
||||
ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.65f);
|
||||
for (int i = 0; i < 4; i++) {
|
||||
ac3 = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.55f);
|
||||
g2d.setComposite(ac3);
|
||||
int x1 = num(-10, width - 10);
|
||||
int y1 = num(5, height - 5);
|
||||
|
Reference in New Issue
Block a user