|
@@ -36,7 +36,7 @@ public class ImageUtil {
|
|
|
|
|
|
private static BufferedImage createImage(String verifyCode) throws IOException, FontFormatException {
|
|
|
BufferedImage image = new BufferedImage(WIDTH, HEIGHT, BufferedImage.TYPE_INT_RGB);
|
|
|
- Graphics graphics = image.getGraphics();
|
|
|
+ Graphics2D graphics = image.createGraphics();
|
|
|
|
|
|
graphics.setColor(Color.WHITE);
|
|
|
graphics.fillRect(0, 0, WIDTH, HEIGHT);
|
|
@@ -50,17 +50,17 @@ public class ImageUtil {
|
|
|
font = font.deriveFont((float) (HEIGHT - 10));
|
|
|
graphics.setFont(font);
|
|
|
|
|
|
- int desX, desY, distance = 16;
|
|
|
+ int desX, desY=HEIGHT-10, distance = 18;
|
|
|
+// 绘制验证码
|
|
|
for (int i = 0; i < verifyCode.length(); i++) {
|
|
|
graphics.setColor(COLORS[RANDOM.nextInt(COLORS.length)]);
|
|
|
- desX = (i + 1) * distance;
|
|
|
- desY = distance + RANDOM.nextInt(HEIGHT - 2 * distance);
|
|
|
- graphics.drawString(Character.toString(verifyCode.charAt(i)), desX, desY);
|
|
|
+ desX = i * distance+18;
|
|
|
+ graphics.drawString(Character.toString(verifyCode.charAt(i)), desX,desY+ RANDOM.nextInt(desY%10));
|
|
|
}
|
|
|
-
|
|
|
- for (int x = 0; x < 150; x++) {
|
|
|
+// 绘制干扰线
|
|
|
+ for (int x = 0; x < 6; x++) {
|
|
|
graphics.setColor(getRandomColor());
|
|
|
- graphics.drawOval(RANDOM.nextInt(WIDTH), RANDOM.nextInt(HEIGHT), 1, 1);
|
|
|
+ graphics.drawLine(RANDOM.nextInt(WIDTH), RANDOM.nextInt(HEIGHT), RANDOM.nextInt(WIDTH), RANDOM.nextInt(HEIGHT));
|
|
|
}
|
|
|
|
|
|
graphics.dispose();
|