public abstract class AbstractCaptcha extends Object implements ICaptcha
| 限定符和类型 | 字段和说明 |
|---|---|
protected Color |
background
背景色
|
protected String |
code
验证码
|
protected char[] |
codeChar
code
|
protected Color |
color
文字颜色
|
protected Font |
font
字体
|
protected CaptchaGenerator |
generator
验证码生成器
|
protected int |
height
图片的高度
|
protected byte[] |
imageBytes
验证码图片
|
protected int |
imageType
图片类型
|
protected int |
interfereCount
验证码干扰元素个数
|
protected int |
len
字符个数
|
protected String |
mimeType
contentType
|
protected AlphaComposite |
textAlpha
文字透明度
|
protected int |
width
图片的宽度
|
| 构造器和说明 |
|---|
AbstractCaptcha(CaptchaDetails captchaDetails) |
AbstractCaptcha(CaptchaDetails captchaDetails,
CaptchaGenerator generator) |
AbstractCaptcha(int width,
int height,
CaptchaGenerator generator,
int interfereCount,
int len) |
AbstractCaptcha(int width,
int height,
CaptchaGenerator generator,
int interfereCount,
int len,
Font font) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
create()
创建验证码
|
protected abstract Image |
createImage(char[] code)
根据生成的code创建验证码图片
|
protected abstract void |
createImageGif(char[] code)
创建验证码gif图
|
protected void |
generateCode()
生成验证码
|
float |
getAlpha(int i,
int j)
获取透明度,从0到1,自动计算步长
|
float |
getAlpha(int i,
int j,
int leng) |
CaptchaGenerator |
getGenerator()
获取验证码生成器
|
BufferedImage |
getImage()
获取验证码图
|
String |
getImageBase64()
获得图片的Base64形式
|
String |
getImageBase64Data()
获取图片带文件格式的 Base64
|
byte[] |
getImageBytes()
获取图形验证码图片bytes
|
String |
getMimeType()
获取图片mimeType
|
String |
getText()
获取验证码内容
|
BufferedImage |
graphicsImage(Color[] fontColor,
char[] strs,
int flag,
int[][] besselXY)
画随机码图
|
static int |
num(int num)
产生0-num的随机数,不包括num
|
static int |
num(int min,
int max) |
void |
setBackground(Color background)
设置背景色
|
void |
setFont(Font font)
自定义字体
|
void |
setGenerator(CaptchaGenerator generator)
设置验证码生成器
|
void |
setTextAlpha(float textAlpha)
设置文字透明度
|
boolean |
verify(String checkedCode)
校验验证码是否一致
|
void |
write(File file)
验证码写出到文件
|
void |
write(OutputStream out)
输出到指定流中
|
void |
write(String path)
验证码写出到文件
|
protected int width
protected int height
protected int interfereCount
protected Font font
protected String code
protected byte[] imageBytes
protected CaptchaGenerator generator
protected Color background
protected AlphaComposite textAlpha
protected int len
protected Color color
protected char[] codeChar
protected int imageType
protected String mimeType
public AbstractCaptcha(int width,
int height,
CaptchaGenerator generator,
int interfereCount,
int len)
public AbstractCaptcha(int width,
int height,
CaptchaGenerator generator,
int interfereCount,
int len,
Font font)
public AbstractCaptcha(CaptchaDetails captchaDetails)
public AbstractCaptcha(CaptchaDetails captchaDetails, CaptchaGenerator generator)
public void write(OutputStream out)
ICaptchapublic void write(String path) throws cn.hutool.core.io.IORuntimeException
path - 文件路径cn.hutool.core.io.IORuntimeException - IO异常public void write(File file) throws cn.hutool.core.io.IORuntimeException
file - 文件cn.hutool.core.io.IORuntimeException - IO异常protected void generateCode()
protected abstract Image createImage(char[] code)
code - 验证码protected abstract void createImageGif(char[] code)
code - 验证码public byte[] getImageBytes()
public BufferedImage getImage()
public String getImageBase64()
public String getImageBase64Data()
public String getMimeType()
public void setFont(Font font)
font - 字体public CaptchaGenerator getGenerator()
public void setGenerator(CaptchaGenerator generator)
generator - 验证码生成器public void setBackground(Color background)
background - 背景色public void setTextAlpha(float textAlpha)
textAlpha - 文字透明度,取值0~1,1表示不透明public BufferedImage graphicsImage(Color[] fontColor, char[] strs, int flag, int[][] besselXY)
fontColor - 随机字体颜色strs - 字符数组flag - 透明度besselXY - 干扰线参数public float getAlpha(int i,
int j)
i - j - public float getAlpha(int i,
int j,
int leng)
public static int num(int min,
int max)
public static int num(int num)
num - 最大值Copyright © 2022. All rights reserved.