优化验证码的效果和干扰

This commit is contained in:
synchronized 2018-07-27 16:18:18 +08:00
parent 92ff9adc04
commit 4dff67843f
2 changed files with 56 additions and 5 deletions

View File

@ -1,8 +1,14 @@
# EasyCaptcha
![GitHub release](https://img.shields.io/github/release/whvcse/EasyCaptcha.svg?style=flat-square)
![GitHub Release Date](https://img.shields.io/github/release-date/whvcse/EasyCaptcha.svg?style=flat-square)
![JitPack](https://img.shields.io/jitpack/v/whvcse/EasyCaptcha.svg?style=flat-square)
![Hex.pm](https://img.shields.io/hexpm/l/plug.svg?style=flat-square)
## 1.简介
  Java图形验证码支持gif验证码可用于Java Web、JavaSE和Android项目。
  Java图形验证码支持gif验证码可用于Java Web、JavaSE项目。
## 2.效果展示
@ -146,4 +152,48 @@ public class MainController {
## 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);
}
}
```

View File

@ -2,6 +2,7 @@ package com.wf.captcha;
import org.junit.Test;
import java.awt.*;
import java.io.File;
import java.io.FileOutputStream;
@ -20,8 +21,8 @@ public class CaptchaTest {
@Test
public void testGIf() throws Exception {
GifCaptcha specCaptcha = new GifCaptcha(130, 48, 5);
System.out.println(specCaptcha.text());
//specCaptcha.out(new FileOutputStream(new File("D:/a/aa.gif")));
GifCaptcha gifCaptcha = new GifCaptcha(130, 48, 5);
System.out.println(gifCaptcha.text());
//gifCaptcha.out(new FileOutputStream(new File("D:/a/aa.gif")));
}
}