优化验证码的效果和干扰
This commit is contained in:
		
							
								
								
									
										54
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										54
									
								
								README.md
									
									
									
									
									
								
							@@ -1,8 +1,14 @@
 | 
				
			|||||||
# EasyCaptcha
 | 
					# EasyCaptcha
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 1.简介
 | 
					## 1.简介
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  Java图形验证码,支持gif验证码,可用于Java Web、JavaSE和Android项目。
 | 
					  Java图形验证码,支持gif验证码,可用于Java Web、JavaSE项目。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## 2.效果展示
 | 
					## 2.效果展示
 | 
				
			||||||
@@ -146,4 +152,48 @@ public class MainController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
## 4.更多设置
 | 
					## 4.更多设置
 | 
				
			||||||
 | 
					
 | 
				
			||||||
###
 | 
					### 4.1.使用Gif验证码
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```java
 | 
				
			||||||
 | 
					public class Test {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        OutputStream outputStream = new FileOutputStream(new File("D:/a/aa.gif"));
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 三个参数分别为宽、高、位数
 | 
				
			||||||
 | 
					        GifCaptcha gifCaptcha = new GifCaptcha(130, 48, 5);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 设置字体
 | 
				
			||||||
 | 
					        gifCaptcha.setFont(new Font("Verdana", Font.PLAIN, 32));  // 有默认字体,可以不用设置
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 生成的验证码
 | 
				
			||||||
 | 
					        String code = gifCaptcha.text();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 输出图片流
 | 
				
			||||||
 | 
					        gifCaptcha.out(outputStream);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					### 4.2.使用png验证码
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```java
 | 
				
			||||||
 | 
					public class Test {
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    public static void main(String[] args) {
 | 
				
			||||||
 | 
					        OutputStream outputStream = new FileOutputStream(new File("D:/a/aa.gif"));
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 三个参数分别为宽、高、位数
 | 
				
			||||||
 | 
					        SpecCaptcha specCaptcha = new SpecCaptcha(130, 48, 5);
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 设置字体
 | 
				
			||||||
 | 
					        specCaptcha.setFont(new Font("Verdana", Font.PLAIN, 32));  // 有默认字体,可以不用设置
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 生成的验证码
 | 
				
			||||||
 | 
					        String code = specCaptcha.text();
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        // 输出图片流
 | 
				
			||||||
 | 
					        specCaptcha.out(outputStream);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
@@ -2,6 +2,7 @@ package com.wf.captcha;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import org.junit.Test;
 | 
					import org.junit.Test;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.awt.*;
 | 
				
			||||||
import java.io.File;
 | 
					import java.io.File;
 | 
				
			||||||
import java.io.FileOutputStream;
 | 
					import java.io.FileOutputStream;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -20,8 +21,8 @@ public class CaptchaTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void testGIf() throws Exception {
 | 
					    public void testGIf() throws Exception {
 | 
				
			||||||
        GifCaptcha specCaptcha = new GifCaptcha(130, 48, 5);
 | 
					        GifCaptcha gifCaptcha = new GifCaptcha(130, 48, 5);
 | 
				
			||||||
        System.out.println(specCaptcha.text());
 | 
					        System.out.println(gifCaptcha.text());
 | 
				
			||||||
        //specCaptcha.out(new FileOutputStream(new File("D:/a/aa.gif")));
 | 
					        //gifCaptcha.out(new FileOutputStream(new File("D:/a/aa.gif")));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user