public class CaptchaImageUtils extends Object
| 构造器和说明 |
|---|
CaptchaImageUtils() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
centerOverlayAndRotateImage(BufferedImage baseBufferedImage,
BufferedImage coverBufferedImage,
double degree) |
static BufferedImage |
concatImage(boolean direction,
int width,
int height,
BufferedImage... imgArr)
拼接图片
|
static BufferedImage |
copyImage(Image img,
int imageType)
拷贝图片
|
static BufferedImage |
copyImage(Image img,
int imageType,
Color backgroundColor)
拷贝图片
|
static Graphics2D |
createGraphics(BufferedImage image,
Color color)
创建画板
|
static BufferedImage |
createTransparentImage(int width,
int height) |
static BufferedImage |
cutImage(BufferedImage oriImage,
BufferedImage templateImage,
int xPos,
int yPos)
通过模板图片抠图(不透明部分)
|
static void |
drawBesselLine(int num,
Color color,
Graphics2D g,
int width,
int height,
ThreadLocalRandom random)
随机画贝塞尔曲线
|
static void |
drawOval(int num,
Color color,
Graphics2D g,
int width,
int height,
Random random)
随机画干扰圆
|
static BufferedImage |
drawWordImg(Color fontColor,
String word,
Font font,
float fontTopCoef,
int imgWidth,
int imgHeight,
float deg) |
static BufferedImage |
genSimpleImgCaptcha(String data,
Font font,
int width,
int height,
float startX,
float startY,
int interferenceLineNum,
int interferencePointNum)
生成简单的验证码图片
|
static Shape |
getImageShape(Image img,
boolean transparent)
将Image图像中的透明/不透明部分转换为Shape图形
|
static Color |
getRandomColor(Random random)
随机获取颜色
|
static boolean |
isJpeg(String type)
后缀是否是jpg
|
static boolean |
isPng(String type)
后缀是否是 png
|
static void |
overlayImage(BufferedImage baseBufferedImage,
BufferedImage coverBufferedImage,
int x,
int y)
图片覆盖(覆盖图压缩到width*height大小,覆盖到底图上)
|
static BufferedImage |
rotateImage(BufferedImage bufferedImage,
double degree)
旋转图片
|
static BufferedImage[] |
splitImage(int pos,
boolean direction,
BufferedImage img)
分隔图片
|
static BufferedImage |
toBufferedImage(Image image,
int imageType)
转换成指定类型的 BufferedImage
|
static BufferedImage |
toBufferedImage(Image image,
String imageType)
转换成指定类型的 BufferedImage
|
static BufferedImage |
wrapFile2BufferedImage(InputStream resource) |
static BufferedImage |
wrapFile2BufferedImage(URL resourceImage) |
public static BufferedImage wrapFile2BufferedImage(URL resourceImage)
public static BufferedImage wrapFile2BufferedImage(InputStream resource)
public static BufferedImage createTransparentImage(int width, int height)
public static void overlayImage(BufferedImage baseBufferedImage, BufferedImage coverBufferedImage, int x, int y)
baseBufferedImage - 底图coverBufferedImage - 覆盖图x - 起始x轴y - 起始y轴public static Shape getImageShape(Image img, boolean transparent) throws InterruptedException
img - 图片信息transparent - 是否透明InterruptedException - 异常public static BufferedImage cutImage(BufferedImage oriImage, BufferedImage templateImage, int xPos, int yPos)
oriImage - 源图片templateImage - 模板图片xPos - 坐标轴xyPos - 坐标轴ypublic static BufferedImage rotateImage(BufferedImage bufferedImage, double degree)
bufferedImage - degree - public static void centerOverlayAndRotateImage(BufferedImage baseBufferedImage, BufferedImage coverBufferedImage, double degree)
public static BufferedImage[] splitImage(int pos, boolean direction, BufferedImage img)
pos - 分隔点direction - true为水平方向, false为垂直方向img - 待分割的图片public static BufferedImage concatImage(boolean direction, int width, int height, BufferedImage... imgArr)
direction - rue为水平方向, false为垂直方向width - 拼接后图片宽度height - 拼接后图片高度imgArr - 拼接的图片数组public static BufferedImage drawWordImg(Color fontColor, String word, Font font, float fontTopCoef, int imgWidth, int imgHeight, float deg)
public static void drawOval(int num,
Color color,
Graphics2D g,
int width,
int height,
Random random)
num - 数量color - 颜色g - Graphics2Dpublic static void drawBesselLine(int num,
Color color,
Graphics2D g,
int width,
int height,
ThreadLocalRandom random)
num - 数量color - 颜色g - Graphics2Dpublic static BufferedImage genSimpleImgCaptcha(String data, Font font, int width, int height, float startX, float startY, int interferenceLineNum, int interferencePointNum)
data - 验证码内容font - 字体包width - 验证码宽度height - 验证码高度startX - 起始XstartY - 起始YinterferenceLineNum - 干扰线数量interferencePointNum - 干扰点数量public static BufferedImage toBufferedImage(Image image, String imageType)
image - imageimageType - imageTypepublic static BufferedImage toBufferedImage(Image image, int imageType)
image - imageimageType - imageTypepublic static BufferedImage copyImage(Image img, int imageType)
img - imgimageType - imageTypepublic static BufferedImage copyImage(Image img, int imageType, Color backgroundColor)
img - imgimageType - imageTypebackgroundColor - backgroundColorpublic static Graphics2D createGraphics(BufferedImage image, Color color)
image - imagecolor - colorpublic static boolean isJpeg(String type)
type - typepublic static boolean isPng(String type)
type - typeCopyright © 2025. All rights reserved.