public abstract class AbstractCaptcha extends Object implements ICaptcha
Modifier and Type | Field and Description |
---|---|
protected Color |
background
背景色
|
protected String |
code
验证码
|
protected Font |
font
字体
|
protected CodeGenerator |
generator
验证码生成器
|
protected int |
height
图片的高度
|
protected byte[] |
imageBytes
验证码图片
|
protected int |
interfereCount
验证码干扰元素个数
|
protected AlphaComposite |
textAlpha
文字透明度
|
protected int |
width
图片的宽度
|
Constructor and Description |
---|
AbstractCaptcha(int width,
int height,
CodeGenerator generator,
int interfereCount)
构造
|
AbstractCaptcha(int width,
int height,
CodeGenerator generator,
int interfereCount,
float size)
构造
|
AbstractCaptcha(int width,
int height,
int codeCount,
int interfereCount)
构造,使用随机验证码生成器生成验证码
|
Modifier and Type | Method and Description |
---|---|
void |
createCode()
创建验证码,实现类需同时生成随机验证码字符串和验证码图片
|
protected abstract Image |
createImage(String code)
根据生成的code创建验证码图片
|
protected void |
generateCode()
生成验证码字符串
|
String |
getCode()
获取验证码的文字内容
|
CodeGenerator |
getGenerator()
获取验证码生成器
|
BufferedImage |
getImage()
获取验证码图
|
String |
getImageBase64()
获得图片的Base64形式
|
String |
getImageBase64Data()
获取图片带文件格式的 Base64
|
byte[] |
getImageBytes()
获取图形验证码图片bytes
|
void |
setBackground(Color background)
设置背景色
|
void |
setFont(Font font)
自定义字体
|
void |
setGenerator(CodeGenerator generator)
设置验证码生成器
|
void |
setTextAlpha(float textAlpha)
设置文字透明度
|
boolean |
verify(String userInputCode)
验证验证码是否正确,建议忽略大小写
|
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 CodeGenerator generator
protected Color background
protected AlphaComposite textAlpha
public AbstractCaptcha(int width, int height, int codeCount, int interfereCount)
width
- 图片宽height
- 图片高codeCount
- 字符个数interfereCount
- 验证码干扰元素个数public AbstractCaptcha(int width, int height, CodeGenerator generator, int interfereCount)
width
- 图片宽height
- 图片高generator
- 验证码生成器interfereCount
- 验证码干扰元素个数public AbstractCaptcha(int width, int height, CodeGenerator generator, int interfereCount, float size)
width
- 图片宽height
- 图片高generator
- 验证码生成器interfereCount
- 验证码干扰元素个数size
- 字体的大小 高度的倍数public void createCode()
ICaptcha
createCode
in interface ICaptcha
protected void generateCode()
protected abstract Image createImage(String code)
code
- 验证码public boolean verify(String userInputCode)
ICaptcha
public void write(String path) throws IORuntimeException
path
- 文件路径IORuntimeException
- IO异常public void write(File file) throws IORuntimeException
file
- 文件IORuntimeException
- IO异常public void write(OutputStream out)
ICaptcha
public byte[] getImageBytes()
public BufferedImage getImage()
public String getImageBase64()
public String getImageBase64Data()
public void setFont(Font font)
font
- 字体public CodeGenerator getGenerator()
public void setGenerator(CodeGenerator generator)
generator
- 验证码生成器public void setBackground(Color background)
background
- 背景色public void setTextAlpha(float textAlpha)
textAlpha
- 文字透明度,取值0~1,1表示不透明Copyright © 2024. All rights reserved.