Package com.wf.captcha.base
Class Captcha
java.lang.Object
com.wf.captcha.base.Randoms
com.wf.captcha.base.Captcha
- Direct Known Subclasses:
ArithmeticCaptchaAbstract,ChineseCaptchaAbstract,GifCaptcha,SpecCaptcha
验证码抽象类
- Author:
- Created by 王帆 on 2018-07-27 上午 10:08.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected Stringprotected intstatic final int[][]static final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected intprotected intstatic final intstatic final intstatic final intstatic final intstatic final intstatic final intprotected intFields inherited from class com.wf.captcha.base.Randoms
ALPHA, CHAR_MAX_INDEX, CHAR_MIN_INDEX, LOWER_MAX_INDEX, LOWER_MIN_INDEX, NUM_MAX_INDEX, RANDOM, UPPER_MAX_INDEX, UPPER_MIN_INDEX -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected char[]alphas()生成随机验证码void检查验证码是否生成,没有则立即生成protected Colorcolor()获取随机常用颜色protected Colorcolor(int fc, int bc) 给定范围获得随机颜色voiddrawBesselLine(int num, Color color, Graphics2D g) 随机画贝塞尔曲线voiddrawBesselLine(int num, Graphics2D g) 随机画贝塞尔曲线voiddrawLine(int num, Color color, Graphics2D g) 随机画干扰线voiddrawLine(int num, Graphics2D g) 随机画干扰线voiddrawOval(int num, Color color, Graphics2D g) 随机画干扰圆voiddrawOval(int num, Graphics2D g) 随机画干扰圆intabstract String获取图片类型getFont()intintgetLen()intgetWidth()abstract booleanout(OutputStream os) 验证码输出,抽象方法,由子类实现voidsetCharType(int charType) voidsetFont(int font) voidsetFont(int font, float size) voidsetFont(int font, int style, float size) voidvoidsetHeight(int height) voidsetLen(int len) voidsetWidth(int width) text()获取当前的验证码char[]textChar()获取当前验证码的字符数组abstract StringtoBase64()输出base64编码输出base64编码
-
Field Details
-
COLOR
public static final int[][] COLOR -
TYPE_DEFAULT
public static final int TYPE_DEFAULT- See Also:
-
TYPE_ONLY_NUMBER
public static final int TYPE_ONLY_NUMBER- See Also:
-
TYPE_ONLY_CHAR
public static final int TYPE_ONLY_CHAR- See Also:
-
TYPE_ONLY_UPPER
public static final int TYPE_ONLY_UPPER- See Also:
-
TYPE_ONLY_LOWER
public static final int TYPE_ONLY_LOWER- See Also:
-
TYPE_NUM_AND_UPPER
public static final int TYPE_NUM_AND_UPPER- See Also:
-
FONT_1
public static final int FONT_1- See Also:
-
FONT_2
public static final int FONT_2- See Also:
-
FONT_3
public static final int FONT_3- See Also:
-
FONT_4
public static final int FONT_4- See Also:
-
FONT_5
public static final int FONT_5- See Also:
-
FONT_6
public static final int FONT_6- See Also:
-
FONT_7
public static final int FONT_7- See Also:
-
FONT_8
public static final int FONT_8- See Also:
-
FONT_9
public static final int FONT_9- See Also:
-
FONT_10
public static final int FONT_10- See Also:
-
len
protected int len -
width
protected int width -
height
protected int height -
charType
protected int charType -
chars
-
-
Constructor Details
-
Captcha
public Captcha()
-
-
Method Details
-
alphas
protected char[] alphas()生成随机验证码- Returns:
- 验证码字符数组
-
color
给定范围获得随机颜色- Parameters:
fc- 0-255bc- 0-255- Returns:
- 随机颜色
-
color
获取随机常用颜色- Returns:
- 随机颜色
-
out
验证码输出,抽象方法,由子类实现- Parameters:
os- 输出流- Returns:
- 是否成功
-
toBase64
输出base64编码- Returns:
- base64编码字符串
-
getContentType
获取图片类型- Returns:
- 图片格式,MIME类型
-
toBase64
输出base64编码- Parameters:
type- 编码头- Returns:
- base64编码字符串
-
text
获取当前的验证码- Returns:
- 字符串
-
textChar
public char[] textChar()获取当前验证码的字符数组- Returns:
- 字符数组
-
checkAlpha
public void checkAlpha()检查验证码是否生成,没有则立即生成 -
drawLine
随机画干扰线- Parameters:
num- 数量g- Graphics2D
-
drawLine
随机画干扰线- Parameters:
num- 数量color- 颜色g- Graphics2D
-
drawOval
随机画干扰圆- Parameters:
num- 数量g- Graphics2D
-
drawOval
随机画干扰圆- Parameters:
num- 数量color- 颜色g- Graphics2D
-
drawBesselLine
随机画贝塞尔曲线- Parameters:
num- 数量g- Graphics2D
-
drawBesselLine
随机画贝塞尔曲线- Parameters:
num- 数量color- 颜色g- Graphics2D
-
getFont
-
setFont
-
setFont
- Throws:
IOExceptionFontFormatException
-
setFont
- Throws:
IOExceptionFontFormatException
-
setFont
- Throws:
IOExceptionFontFormatException
-
getLen
public int getLen() -
setLen
public void setLen(int len) -
getWidth
public int getWidth() -
setWidth
public void setWidth(int width) -
getHeight
public int getHeight() -
setHeight
public void setHeight(int height) -
getCharType
public int getCharType() -
setCharType
public void setCharType(int charType)
-