public class CaptchaUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
private int |
captchaLen
验证码长度
默认4个字符
|
private char[] |
code
验证码来源
|
private int |
disturbLine
干扰线条数
默认3条
|
private String[] |
fontNames
字体
|
private int |
fontsize
验证码图片字体大小
默认17
|
private int[] |
fontStyles
字体样式
|
private int |
height
验证码图片高度
|
private int |
width
验证码图片宽度
|
| 构造器和说明 |
|---|
CaptchaUtil() |
CaptchaUtil(int captchaLen)
指定验证码长度
|
CaptchaUtil(int captchaLen,
int width,
int height)
指定验证码长度、图片宽度、高度
|
| 限定符和类型 | 方法和说明 |
|---|---|
private void |
drawDisturbLine(Graphics g)
为验证码图片画一些干扰线
|
static void |
generateCaptcha(Integer captchaLen,
Integer width,
Integer height,
String captchaType,
javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
直接调用这个方法
|
String |
generatorCaptcha()
生成验证码
|
BufferedImage |
generatorCaptchaImage(String captcha,
boolean drawline)
生成验证码图片
|
BufferedImage |
generatorRotateCaptchaImage(String captcha,
boolean drawline)
获得旋转字体的验证码图片
|
int |
getCaptchaLen() |
int |
getDisturbLine() |
int |
getFontsize() |
int |
getHeight() |
private Color |
getRandomColor() |
private BufferedImage |
getRotateImage(char c)
获取一张旋转的图片
|
private double |
getTheta() |
int |
getWidth() |
void |
setCaptchaLen(int captchaLen)
设置验证码字符个数
|
void |
setDisturbLine(int disturbLine)
设置干扰线条数
|
void |
setFontsize(int fontsize)
设置字体大小
|
void |
setHeight(int height)
设置图片高度
|
void |
setWidth(int width)
设置图片宽度
|
private final char[] code
private final String[] fontNames
private final int[] fontStyles
private int captchaLen
private int fontsize
private int width
private int height
private int disturbLine
public CaptchaUtil()
public CaptchaUtil(int captchaLen)
captchaLen - 验证码长度public CaptchaUtil(int captchaLen,
int width,
int height)
captchaLen - width - height - public BufferedImage generatorCaptchaImage(String captcha, boolean drawline)
captcha - 要画的验证码drawline - 是否画干扰线public BufferedImage generatorRotateCaptchaImage(String captcha, boolean drawline)
captcha - drawline - 是否画干扰线public String generatorCaptcha()
private void drawDisturbLine(Graphics g)
g - private BufferedImage getRotateImage(char c)
c - 要画的字符private Color getRandomColor()
private double getTheta()
public int getCaptchaLen()
public void setCaptchaLen(int captchaLen)
captchaLen - public int getFontsize()
public void setFontsize(int fontsize)
fontsize - public int getWidth()
public void setWidth(int width)
width - public int getHeight()
public void setHeight(int height)
height - public int getDisturbLine()
public void setDisturbLine(int disturbLine)
disturbLine - public static void generateCaptcha(Integer captchaLen, Integer width, Integer height, String captchaType, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws IOException
captchaLen - width - height - captchaType - request - response - IOExceptionCopyright © 2023. All rights reserved.