Parcourir la source

验证码样式调整,清晰度等优化

ZhangWenQiang il y a 6 ans
Parent
commit
2be5f1c8c3

+ 9 - 5
src/main/java/com/jeeplus/core/servlet/ValidateCodeServlet.java

@@ -30,8 +30,12 @@ public class ValidateCodeServlet extends HttpServlet {
 	
 	public static final String VALIDATE_CODE = "validateCode";
 	
-	private int w = 70;
-	private int h = 26;
+	private int w = 95;
+	private int h = 40;
+	/**
+	 * 干扰线数量
+	 */
+	private int lineSize = 10;
 	
 	public ValidateCodeServlet() {
 		super();
@@ -118,7 +122,7 @@ public class ValidateCodeServlet extends HttpServlet {
 		g.setColor(getRandColor(220,250)); 
 		g.fillRect(0, 0, w, h);
 		// 加入干扰线条
-		for (int i = 0; i < 8; i++) {
+		for (int i = 0; i < lineSize; i++) {
 			g.setColor(getRandColor(40,150));
 			Random random = new Random();
 			int x = random.nextInt(w);
@@ -138,8 +142,8 @@ public class ValidateCodeServlet extends HttpServlet {
 		StringBuilder s = new StringBuilder();
 		for (int i = 0; i < 4; i++) {
 			String r = String.valueOf(codeSeq[random.nextInt(codeSeq.length)]);//random.nextInt(10));
-			g.setColor(new Color(50 + random.nextInt(100), 50 + random.nextInt(100), 50 + random.nextInt(100)));
-			g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)],Font.BOLD,26)); 
+			g.setColor(new Color(random.nextInt(101), random.nextInt(111), random.nextInt(121)));
+			g.setFont(new Font(fontTypes[random.nextInt(fontTypes.length)],Font.BOLD,24));
 			g.drawString(r, 15 * i + 5, 19 + random.nextInt(8));
 //			g.drawString(r, i*w/4, h-5);
 			s.append(r);