public abstract class AbstractProvider extends Object implements CaptchaProvider
createImage(String) 方法生成图片对象| Modifier and Type | Field and Description |
|---|---|
protected Color |
background
背景色
|
protected String |
code
验证码
|
protected Font |
font
字体
|
protected CodeStrategy |
generator
验证码生成器
|
protected int |
height
图片的高度
|
protected byte[] |
imageBytes
验证码图片
|
protected int |
interfereCount
验证码干扰元素个数
|
protected AlphaComposite |
textAlpha
文字透明度
|
protected int |
width
图片的宽度
|
| Constructor and Description |
|---|
AbstractProvider(int width,
int height,
CodeStrategy generator,
int interfereCount)
构造
|
AbstractProvider(int width,
int height,
int codeCount,
int interfereCount)
构造,使用随机验证码生成器生成验证码
|
| Modifier and Type | Method and Description |
|---|---|
void |
create()
创建验证码,实现类需同时生成随机验证码字符串和验证码图片
|
protected abstract Image |
createImage(String code)
根据生成的code创建验证码图片
|
protected void |
generateCode()
生成验证码字符串
|
String |
get()
获取验证码的文字内容
|
CodeStrategy |
getGenerator()
获取验证码生成器
|
BufferedImage |
getImage()
获取验证码图
|
String |
getImageBase64()
获得图片的Base64形式
|
byte[] |
getImageBytes()
获取图形验证码图片bytes
|
void |
setBackground(Color background)
设置背景色
|
void |
setFont(Font font)
自定义字体
|
void |
setGenerator(CodeStrategy generator)
设置验证码生成器
|
void |
setTextAlpha(float textAlpha)
设置文字透明度
|
boolean |
verify(String inputCode)
验证验证码是否正确,建议忽略大小写
|
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 CodeStrategy generator
protected Color background
protected AlphaComposite textAlpha
public AbstractProvider(int width,
int height,
int codeCount,
int interfereCount)
width - 图片宽height - 图片高codeCount - 字符个数interfereCount - 验证码干扰元素个数public AbstractProvider(int width,
int height,
CodeStrategy generator,
int interfereCount)
width - 图片宽height - 图片高generator - 验证码生成器interfereCount - 验证码干扰元素个数public void create()
CaptchaProvidercreate in interface CaptchaProviderprotected void generateCode()
protected abstract Image createImage(String code)
code - 验证码public String get()
CaptchaProviderget in interface CaptchaProviderpublic boolean verify(String inputCode)
CaptchaProviderverify in interface CaptchaProviderinputCode - 用户输入的验证码public void write(String path) throws org.aoju.bus.core.lang.exception.InstrumentException
path - 文件路径org.aoju.bus.core.lang.exception.InstrumentException - IO异常public void write(File file) throws org.aoju.bus.core.lang.exception.InstrumentException
file - 文件org.aoju.bus.core.lang.exception.InstrumentException - IO异常public void write(OutputStream out)
CaptchaProviderwrite in interface CaptchaProviderout - 目标流public byte[] getImageBytes()
public BufferedImage getImage()
public String getImageBase64()
public void setFont(Font font)
font - 字体public CodeStrategy getGenerator()
public void setGenerator(CodeStrategy generator)
generator - 验证码生成器public void setBackground(Color background)
background - 背景色public void setTextAlpha(float textAlpha)
textAlpha - 文字透明度,取值0~1,1表示不透明Copyright © 2021. All rights reserved.