From 4dff67843f97f2433793083de8ab2bdeef53e536 Mon Sep 17 00:00:00 2001 From: synchronized Date: Fri, 27 Jul 2018 16:18:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=AA=8C=E8=AF=81=E7=A0=81?= =?UTF-8?q?=E7=9A=84=E6=95=88=E6=9E=9C=E5=92=8C=E5=B9=B2=E6=89=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 54 ++++++++++++++++++- src/test/java/com/wf/captcha/CaptchaTest.java | 7 +-- 2 files changed, 56 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c213501..e6ce35e 100644 --- a/README.md +++ b/README.md @@ -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); + } +} +``` \ No newline at end of file diff --git a/src/test/java/com/wf/captcha/CaptchaTest.java b/src/test/java/com/wf/captcha/CaptchaTest.java index 641bf70..2385e9d 100644 --- a/src/test/java/com/wf/captcha/CaptchaTest.java +++ b/src/test/java/com/wf/captcha/CaptchaTest.java @@ -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"))); } }