public class ImgUtil extends Object
| Modifier and Type | Field and Description |
|---|---|
static String |
IMAGE_TYPE_BMP
英文Bitmap(位图)的简写,它是Windows操作系统中的标准图像文件格式:BMP
|
static String |
IMAGE_TYPE_GIF
图形交换格式:GIF
|
static String |
IMAGE_TYPE_JPEG
联合照片专家组:JPEG
|
static String |
IMAGE_TYPE_JPG
联合照片专家组:JPG
|
static String |
IMAGE_TYPE_PNG
可移植网络图形:PNG
|
static String |
IMAGE_TYPE_PSD
Photoshop的专用格式:PSD
|
| Constructor and Description |
|---|
ImgUtil() |
| Modifier and Type | Method and Description |
|---|---|
static BufferedImage |
backgroundRemoval(BufferedImage bufferedImage,
Color override,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static BufferedImage |
backgroundRemoval(ByteArrayOutputStream outputStream,
Color override,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static boolean |
backgroundRemoval(File input,
File output,
Color override,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static boolean |
backgroundRemoval(File input,
File output,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static boolean |
backgroundRemoval(String inputPath,
String outputPath,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static void |
binary(File srcImageFile,
File destImageFile)
彩色转为黑白二值化图片,根据目标文件扩展名确定转换后的格式
|
static Image |
binary(Image srcImage)
彩色转为黑白二值化图片
|
static void |
binary(Image srcImage,
File outFile)
彩色转为黑白二值化图片,根据目标文件扩展名确定转换后的格式
|
static void |
binary(Image srcImage,
ImageOutputStream destImageStream,
String imageType)
彩色转为黑白二值化图片
此方法并不关闭流,输出JPG格式 |
static void |
binary(ImageInputStream srcStream,
ImageOutputStream destStream,
String imageType)
彩色转为黑白黑白二值化图片
此方法并不关闭流 |
static void |
binary(Image srcImage,
OutputStream out,
String imageType)
彩色转为黑白二值化图片
此方法并不关闭流,输出JPG格式 |
static void |
binary(InputStream srcStream,
OutputStream destStream,
String imageType)
彩色转为黑白二值化图片
此方法并不关闭流 |
static BufferedImage |
castToBufferedImage(Image img,
String imageType)
|
static RenderedImage |
castToRenderedImage(Image img,
String imageType)
|
static BufferedImage |
colorConvert(ColorSpace colorSpace,
BufferedImage image)
图片颜色转换
可以使用灰度 (gray)等 |
static void |
compress(File imageFile,
File outFile,
float quality)
压缩图像,输出图像只支持jpg文件
|
static void |
convert(File srcImageFile,
File destImageFile)
图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
|
static void |
convert(Image srcImage,
String formatName,
ImageOutputStream destImageStream)
图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static void |
convert(Image srcImage,
String formatName,
ImageOutputStream destImageStream,
boolean isSrcPng)
Deprecated.
|
static void |
convert(InputStream srcStream,
String formatName,
OutputStream destStream)
图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static BufferedImage |
copyImage(Image img,
int imageType)
将已有Image复制新的一份出来
|
static BufferedImage |
copyImage(Image img,
int imageType,
Color backgroundColor)
将已有Image复制新的一份出来
|
static BufferedImage |
createCompatibleImage(int width,
int height,
int transparency)
创建与当前设备颜色模式兼容的
BufferedImage |
static Font |
createFont(File fontFile)
|
static Font |
createFont(InputStream fontStream)
|
static Graphics2D |
createGraphics(BufferedImage image,
Color color)
|
static void |
createImage(String str,
Font font,
Color backgroundColor,
Color fontColor,
ImageOutputStream out)
根据文字创建PNG图片
|
static BufferedImage |
createImage(String str,
Font font,
Color backgroundColor,
Color fontColor,
int imageType)
根据文字创建图片
|
static void |
createTransparentImage(String str,
Font font,
Color fontColor,
ImageOutputStream out)
根据文字创建透明背景的PNG图片
|
static void |
cut(File srcImgFile,
File destImgFile,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割)
|
static void |
cut(Image srcImage,
File destFile,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static void |
cut(Image srcImage,
ImageOutputStream destImageStream,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static void |
cut(ImageInputStream srcStream,
ImageOutputStream destStream,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static Image |
cut(Image srcImage,
int x,
int y)
图像切割(按指定起点坐标和宽高切割),填充满整个图片(直径取长宽最小值)
|
static Image |
cut(Image srcImage,
int x,
int y,
int radius)
图像切割(按指定起点坐标和宽高切割)
|
static void |
cut(Image srcImage,
OutputStream out,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static Image |
cut(Image srcImage,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割)
|
static void |
cut(InputStream srcStream,
OutputStream destStream,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static BufferedImage |
filter(BufferedImageOp op,
BufferedImage image)
图片过滤转换
|
static Image |
filter(ImageFilter filter,
Image image)
图片滤镜,借助
ImageFilter实现,实现不同的图片滤镜 |
static void |
flip(File imageFile,
File outFile)
水平翻转图像
|
static Image |
flip(Image image)
水平翻转图像
|
static void |
flip(Image image,
File outFile)
水平翻转图像
|
static void |
flip(Image image,
ImageOutputStream out)
水平翻转图像,写出格式为JPG
|
static void |
flip(Image image,
OutputStream out)
水平翻转图像
|
static void |
flush(Image image)
刷新和释放
Image 资源 |
static Color |
getColor(int rgb)
获取一个RGB值对应的颜色
|
static Color |
getColor(String colorName)
将颜色值转换成具体的颜色类型 汇集了常用的颜色集,支持以下几种形式:
1.
|
static Image |
getImage(URL url)
从URL中获取或读取图片对象
|
static ImageInputStream |
getImageInputStream(InputStream in)
|
static ImageOutputStream |
getImageOutputStream(File outFile)
|
static ImageOutputStream |
getImageOutputStream(OutputStream out)
|
static String |
getMainColor(BufferedImage image,
int[]... rgbFilters)
获取给定图片的主色调,背景填充用
|
static Point |
getPointBaseCentre(Rectangle rectangle,
int backgroundWidth,
int backgroundHeight)
获得修正后的矩形坐标位置,变为以背景中心为基准坐标(即x,y == 0,0时,处于背景正中)
|
static ImageReader |
getReader(String type)
|
static Rectangle2D |
getRectangle(String str,
Font font)
获取font的样式应用在str上的整个矩形
|
static ImageWriter |
getWriter(Image img,
String formatName)
根据给定的Image对象和格式获取对应的
ImageWriter,如果未找到合适的Writer,返回null |
static ImageWriter |
getWriter(String formatName)
根据给定的图片格式或者扩展名获取
ImageWriter,如果未找到合适的Writer,返回null |
static void |
gray(File srcImageFile,
File destImageFile)
彩色转为黑白
|
static Image |
gray(Image srcImage)
彩色转为黑白
|
static void |
gray(Image srcImage,
File outFile)
彩色转为黑白
|
static void |
gray(Image srcImage,
ImageOutputStream destImageStream)
彩色转为黑白
此方法并不关闭流 |
static void |
gray(ImageInputStream srcStream,
ImageOutputStream destStream)
彩色转为黑白
此方法并不关闭流 |
static void |
gray(Image srcImage,
OutputStream out)
彩色转为黑白
此方法并不关闭流 |
static void |
gray(InputStream srcStream,
OutputStream destStream)
彩色转为黑白
此方法并不关闭流 |
static Color |
hexToColor(String hex)
16进制的颜色值转换为Color对象,例如#fcf6d6
|
static void |
pressImage(File srcImageFile,
File destImageFile,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
|
static void |
pressImage(Image srcImage,
File outFile,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static Image |
pressImage(Image srcImage,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressImage(Image srcImage,
ImageOutputStream destImageStream,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static Image |
pressImage(Image srcImage,
Image pressImg,
Rectangle rectangle,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressImage(ImageInputStream srcStream,
ImageOutputStream destStream,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressImage(Image srcImage,
OutputStream out,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressImage(InputStream srcStream,
OutputStream destStream,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressText(File imageFile,
File destFile,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
|
static void |
pressText(Image srcImage,
File destFile,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(Image srcImage,
ImageOutputStream destImageStream,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(ImageInputStream srcStream,
ImageOutputStream destStream,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(Image srcImage,
OutputStream to,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
static Image |
pressText(Image srcImage,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(InputStream srcStream,
OutputStream destStream,
String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
static Color |
randomColor()
生成随机颜色
|
static Color |
randomColor(Color compareColor)
生成随机颜色,与指定颜色有一定的区分度
|
static Color |
randomColor(Color compareColor,
int minDistance)
生成随机颜色,与指定颜色有一定的区分度
|
static Color |
randomColor(Random random)
生成随机颜色
|
static BufferedImage |
read(File imageFile)
从文件中读取图片
|
static BufferedImage |
read(ImageInputStream imageStream)
从图片流中读取图片
|
static BufferedImage |
read(InputStream imageStream)
从流中读取图片
|
static BufferedImage |
read(Resource resource)
从
Resource中读取图片 |
static BufferedImage |
read(String imageFilePath)
从文件中读取图片,请使用绝对路径,使用相对路径会相对于ClassPath
|
static BufferedImage |
read(URL imageUrl)
从URL中读取图片
|
static void |
rotate(File imageFile,
int degree,
File outFile)
旋转图片为指定角度
此方法不会关闭输出流 |
static Image |
rotate(Image image,
int degree)
旋转图片为指定角度
来自:http://blog.51cto.com/cping1982/130066 |
static void |
rotate(Image image,
int degree,
File outFile)
旋转图片为指定角度
此方法不会关闭输出流 |
static void |
rotate(Image image,
int degree,
ImageOutputStream out)
旋转图片为指定角度
此方法不会关闭输出流,输出格式为JPG |
static void |
rotate(Image image,
int degree,
OutputStream out)
旋转图片为指定角度
此方法不会关闭输出流 |
static void |
scale(File srcImageFile,
File destImageFile,
float scale)
缩放图像(按比例缩放),目标文件的扩展名决定目标文件类型
|
static void |
scale(File srcImageFile,
File destImageFile,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认格式与源图片相同,无法识别原图片默认JPG |
static void |
scale(Image srcImg,
File destFile,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static Image |
scale(Image srcImg,
float scale)
缩放图像(按比例缩放)
|
static void |
scale(Image srcImg,
ImageOutputStream destImageStream,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(Image srcImage,
ImageOutputStream destImageStream,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(ImageInputStream srcStream,
ImageOutputStream destStream,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(ImageInputStream srcStream,
ImageOutputStream destStream,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static Image |
scale(Image srcImg,
int width,
int height)
缩放图像(按长宽缩放)
注意:目标长宽与原图不成比例会变形 |
static Image |
scale(Image srcImage,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式 |
static void |
scale(Image srcImg,
OutputStream out,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(InputStream srcStream,
OutputStream destStream,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(InputStream srcStream,
OutputStream destStream,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
slice(File srcImageFile,
File descDir,
int destWidth,
int destHeight)
图像切片(指定切片的宽度和高度)
|
static void |
slice(Image srcImage,
File descDir,
int destWidth,
int destHeight)
图像切片(指定切片的宽度和高度)
|
static void |
sliceByRowsAndCols(File srcImageFile,
File destDir,
int rows,
int cols)
图像切割(指定切片的行数和列数)
|
static void |
sliceByRowsAndCols(File srcImageFile,
File destDir,
String format,
int rows,
int cols)
图像切割(指定切片的行数和列数)
|
static void |
sliceByRowsAndCols(Image srcImage,
File destDir,
int rows,
int cols)
图像切割(指定切片的行数和列数),默认RGB模式
|
static void |
sliceByRowsAndCols(Image srcImage,
File destDir,
String format,
int rows,
int cols)
图像切割(指定切片的行数和列数),默认RGB模式
|
static String |
toBase64(Image image,
String imageType)
将图片对象转换为Base64形式
|
static String |
toBase64DataUri(Image image,
String imageType)
将图片对象转换为Base64的Data URI形式,格式为:data:image/[imageType];base64,[data]
|
static BufferedImage |
toBufferedImage(Image img)
Deprecated.
|
static BufferedImage |
toBufferedImage(Image image,
int imageType)
|
static BufferedImage |
toBufferedImage(Image image,
int imageType,
Color backgroundColor)
|
static BufferedImage |
toBufferedImage(Image image,
String imageType)
Image 转 BufferedImage如果源图片的RGB模式与目标模式一致,则直接转换,否则重新绘制 默认的,png图片使用 BufferedImage.TYPE_INT_ARGB模式,其它使用 BufferedImage.TYPE_INT_RGB 模式 |
static BufferedImage |
toBufferedImage(Image image,
String imageType,
Color backgroundColor)
Image 转 BufferedImage如果源图片的RGB模式与目标模式一致,则直接转换,否则重新绘制 默认的,png图片使用 BufferedImage.TYPE_INT_ARGB模式,其它使用 BufferedImage.TYPE_INT_RGB 模式 |
static byte[] |
toBytes(Image image,
String imageType)
将图片对象转换为bytes形式
|
static String |
toHex(Color color)
Color对象转16进制表示,例如#fcf6d6
|
static String |
toHex(int r,
int g,
int b)
RGB颜色值转换成十六进制颜色码
|
static BufferedImage |
toImage(byte[] imageBytes)
将的图像bytes转为
BufferedImage |
static BufferedImage |
toImage(String base64)
将Base64编码的图像信息转为
BufferedImage |
static RenderedImage |
toRenderedImage(Image img)
Deprecated.
|
static ByteArrayInputStream |
toStream(Image image,
String imageType)
将图片对象转换为InputStream形式
|
static BufferedImage |
transform(AffineTransform xform,
BufferedImage image)
转换图片
可以使用一系列平移 (translation)、缩放 (scale)、翻转 (flip)、旋转 (rotation) 和错切 (shear) 来构造仿射变换。 |
static void |
write(Image image,
File targetFile)
写出图像为目标文件扩展名对应的格式
|
static boolean |
write(Image image,
ImageWriter writer,
ImageOutputStream output,
float quality)
通过
ImageWriter写出图片到输出流 |
static void |
write(ImageInputStream srcStream,
String formatName,
ImageOutputStream destStream)
按照目标格式写出图像:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static boolean |
write(Image image,
String imageType,
ImageOutputStream destImageStream)
写出图像为指定格式:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static boolean |
write(Image image,
String imageType,
ImageOutputStream destImageStream,
float quality)
写出图像为指定格式
|
static boolean |
write(Image image,
String imageType,
ImageOutputStream destImageStream,
float quality,
Color backgroundColor)
写出图像为指定格式
|
static void |
write(Image image,
String imageType,
OutputStream out)
写出图像:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static void |
writeJpg(Image image,
ImageOutputStream destImageStream)
写出图像为JPG格式
|
static void |
writeJpg(Image image,
OutputStream out)
写出图像为JPG格式
|
static void |
writePng(Image image,
ImageOutputStream destImageStream)
写出图像为PNG格式
|
static void |
writePng(Image image,
OutputStream out)
写出图像为PNG格式
|
public static final String IMAGE_TYPE_GIF
public static final String IMAGE_TYPE_JPG
public static final String IMAGE_TYPE_JPEG
public static final String IMAGE_TYPE_BMP
public static final String IMAGE_TYPE_PNG
public static final String IMAGE_TYPE_PSD
public static void scale(File srcImageFile, File destImageFile, float scale)
srcImageFile - 源图像文件destImageFile - 缩放后的图像文件,扩展名决定目标类型scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小public static void scale(InputStream srcStream, OutputStream destStream, float scale)
srcStream - 源图像来源流destStream - 缩放后的图像写出到的流scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小public static void scale(ImageInputStream srcStream, ImageOutputStream destStream, float scale)
srcStream - 源图像来源流destStream - 缩放后的图像写出到的流scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小public static void scale(Image srcImg, File destFile, float scale) throws IORuntimeException
srcImg - 源图像来源流,使用结束后需手动调用flush(Image)释放资源destFile - 缩放后的图像写出到的流scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小IORuntimeException - IO异常public static void scale(Image srcImg, OutputStream out, float scale) throws IORuntimeException
srcImg - 源图像来源流,使用结束后需手动调用flush(Image)释放资源out - 缩放后的图像写出到的流scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小IORuntimeException - IO异常public static void scale(Image srcImg, ImageOutputStream destImageStream, float scale) throws IORuntimeException
srcImg - 源图像来源流,使用结束后需手动调用flush(Image)释放资源destImageStream - 缩放后的图像写出到的流scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小IORuntimeException - IO异常public static Image scale(Image srcImg, float scale)
srcImg - 源图像来源流,使用结束后需手动调用flush(Image)释放资源scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小Imagepublic static Image scale(Image srcImg, int width, int height)
srcImg - 源图像来源流,使用结束后需手动调用flush(Image)释放资源width - 目标宽度height - 目标高度Imagepublic static void scale(File srcImageFile, File destImageFile, int width, int height, Color fixedColor) throws IORuntimeException
srcImageFile - 源图像文件地址destImageFile - 缩放后的图像地址width - 缩放后的宽度height - 缩放后的高度fixedColor - 补充的颜色,不补充为nullIORuntimeException - IO异常public static void scale(InputStream srcStream, OutputStream destStream, int width, int height, Color fixedColor) throws IORuntimeException
srcStream - 源图像流destStream - 缩放后的图像目标流width - 缩放后的宽度height - 缩放后的高度fixedColor - 比例不对时补充的颜色,不补充为nullIORuntimeException - IO异常public static void scale(ImageInputStream srcStream, ImageOutputStream destStream, int width, int height, Color fixedColor) throws IORuntimeException
srcStream - 源图像流destStream - 缩放后的图像目标流width - 缩放后的宽度height - 缩放后的高度fixedColor - 比例不对时补充的颜色,不补充为nullIORuntimeException - IO异常public static void scale(Image srcImage, ImageOutputStream destImageStream, int width, int height, Color fixedColor) throws IORuntimeException
srcImage - 源图像destImageStream - 缩放后的图像目标流width - 缩放后的宽度height - 缩放后的高度fixedColor - 比例不对时补充的颜色,不补充为nullIORuntimeException - IO异常public static Image scale(Image srcImage, int width, int height, Color fixedColor)
srcImage - 源图像width - 缩放后的宽度height - 缩放后的高度fixedColor - 比例不对时补充的颜色,不补充为nullImagepublic static void cut(File srcImgFile, File destImgFile, Rectangle rectangle)
srcImgFile - 源图像文件destImgFile - 切片后的图像文件rectangle - 矩形对象,表示矩形区域的x,y,width,heightpublic static void cut(InputStream srcStream, OutputStream destStream, Rectangle rectangle)
srcStream - 源图像流destStream - 切片后的图像输出流rectangle - 矩形对象,表示矩形区域的x,y,width,heightpublic static void cut(ImageInputStream srcStream, ImageOutputStream destStream, Rectangle rectangle)
srcStream - 源图像流destStream - 切片后的图像输出流rectangle - 矩形对象,表示矩形区域的x,y,width,heightpublic static void cut(Image srcImage, File destFile, Rectangle rectangle) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源destFile - 输出的文件rectangle - 矩形对象,表示矩形区域的x,y,width,heightIORuntimeException - IO异常public static void cut(Image srcImage, OutputStream out, Rectangle rectangle) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源out - 切片后的图像输出流rectangle - 矩形对象,表示矩形区域的x,y,width,heightIORuntimeException - IO异常public static void cut(Image srcImage, ImageOutputStream destImageStream, Rectangle rectangle) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源destImageStream - 切片后的图像输出流rectangle - 矩形对象,表示矩形区域的x,y,width,heightIORuntimeException - IO异常public static Image cut(Image srcImage, Rectangle rectangle)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源rectangle - 矩形对象,表示矩形区域的x,y,width,heightBufferedImagepublic static Image cut(Image srcImage, int x, int y)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源x - 原图的x坐标起始位置y - 原图的y坐标起始位置Imagepublic static Image cut(Image srcImage, int x, int y, int radius)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源x - 原图的x坐标起始位置y - 原图的y坐标起始位置radius - 半径,小于0表示填充满整个图片(直径取长宽最小值)Imagepublic static void slice(File srcImageFile, File descDir, int destWidth, int destHeight)
srcImageFile - 源图像descDir - 切片目标文件夹destWidth - 目标切片宽度。默认200destHeight - 目标切片高度。默认150public static void slice(Image srcImage, File descDir, int destWidth, int destHeight)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源descDir - 切片目标文件夹destWidth - 目标切片宽度。默认200destHeight - 目标切片高度。默认150public static void sliceByRowsAndCols(File srcImageFile, File destDir, int rows, int cols)
srcImageFile - 源图像文件destDir - 切片目标文件夹rows - 目标切片行数。默认2,必须是范围 [1, 20] 之内cols - 目标切片列数。默认2,必须是范围 [1, 20] 之内public static void sliceByRowsAndCols(File srcImageFile, File destDir, String format, int rows, int cols)
srcImageFile - 源图像文件destDir - 切片目标文件夹format - 目标文件格式rows - 目标切片行数。默认2,必须是范围 [1, 20] 之内cols - 目标切片列数。默认2,必须是范围 [1, 20] 之内public static void sliceByRowsAndCols(Image srcImage, File destDir, int rows, int cols)
srcImage - 源图像,如果非BufferedImage,则默认使用RGB模式destDir - 切片目标文件夹rows - 目标切片行数。默认2,必须是范围 [1, 20] 之内cols - 目标切片列数。默认2,必须是范围 [1, 20] 之内public static void sliceByRowsAndCols(Image srcImage, File destDir, String format, int rows, int cols)
srcImage - 源图像,如果非BufferedImage,则默认使用RGB模式destDir - 切片目标文件夹format - 目标文件格式rows - 目标切片行数。默认2,必须是范围 [1, 20] 之内cols - 目标切片列数。默认2,必须是范围 [1, 20] 之内public static void convert(File srcImageFile, File destImageFile)
srcImageFile - 源图像文件destImageFile - 目标图像文件public static void convert(InputStream srcStream, String formatName, OutputStream destStream)
srcStream - 源图像流formatName - 包含格式非正式名称的 String:如JPG、JPEG、GIF等destStream - 目标图像输出流public static void convert(Image srcImage, String formatName, ImageOutputStream destImageStream)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源formatName - 包含格式非正式名称的 String:如JPG、JPEG、GIF等destImageStream - 目标图像输出流@Deprecated public static void convert(Image srcImage, String formatName, ImageOutputStream destImageStream, boolean isSrcPng)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源formatName - 包含格式非正式名称的 String:如JPG、JPEG、GIF等destImageStream - 目标图像输出流isSrcPng - 源图片是否为PNG格式(参数无效)public static void gray(File srcImageFile, File destImageFile)
srcImageFile - 源图像地址destImageFile - 目标图像地址public static void gray(InputStream srcStream, OutputStream destStream)
srcStream - 源图像流destStream - 目标图像流public static void gray(ImageInputStream srcStream, ImageOutputStream destStream)
srcStream - 源图像流destStream - 目标图像流public static void gray(Image srcImage, File outFile)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源outFile - 目标文件public static void gray(Image srcImage, OutputStream out)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源out - 目标图像流public static void gray(Image srcImage, ImageOutputStream destImageStream) throws IORuntimeException
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源destImageStream - 目标图像流IORuntimeException - IO异常public static Image gray(Image srcImage)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源Image灰度后的图片public static void binary(File srcImageFile, File destImageFile)
srcImageFile - 源图像地址destImageFile - 目标图像地址public static void binary(InputStream srcStream, OutputStream destStream, String imageType)
srcStream - 源图像流destStream - 目标图像流imageType - 图片格式(扩展名)public static void binary(ImageInputStream srcStream, ImageOutputStream destStream, String imageType)
srcStream - 源图像流destStream - 目标图像流imageType - 图片格式(扩展名)public static void binary(Image srcImage, File outFile)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源outFile - 目标文件public static void binary(Image srcImage, OutputStream out, String imageType)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源out - 目标图像流imageType - 图片格式(扩展名)public static void binary(Image srcImage, ImageOutputStream destImageStream, String imageType) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源destImageStream - 目标图像流imageType - 图片格式(扩展名)IORuntimeException - IO异常public static Image binary(Image srcImage)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源Image二值化后的图片public static void pressText(File imageFile, File destFile, String pressText, Color color, Font font, int x, int y, float alpha)
imageFile - 源图像文件destFile - 目标图像文件pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressText(InputStream srcStream, OutputStream destStream, String pressText, Color color, Font font, int x, int y, float alpha)
srcStream - 源图像流destStream - 目标图像流pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressText(ImageInputStream srcStream, ImageOutputStream destStream, String pressText, Color color, Font font, int x, int y, float alpha)
srcStream - 源图像流destStream - 目标图像流pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressText(Image srcImage, File destFile, String pressText, Color color, Font font, int x, int y, float alpha) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源destFile - 目标流pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static void pressText(Image srcImage, OutputStream to, String pressText, Color color, Font font, int x, int y, float alpha) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源to - 目标流pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static void pressText(Image srcImage, ImageOutputStream destImageStream, String pressText, Color color, Font font, int x, int y, float alpha) throws IORuntimeException
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源destImageStream - 目标图像流pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static Image pressText(Image srcImage, String pressText, Color color, Font font, int x, int y, float alpha)
srcImage - 源图像,使用结束后需手动调用flush(Image)释放资源pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息,如果默认则为nullx - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressImage(File srcImageFile, File destImageFile, Image pressImg, int x, int y, float alpha)
srcImageFile - 源图像文件destImageFile - 目标图像文件pressImg - 水印图片x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressImage(InputStream srcStream, OutputStream destStream, Image pressImg, int x, int y, float alpha)
srcStream - 源图像流destStream - 目标图像流pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressImage(ImageInputStream srcStream, ImageOutputStream destStream, Image pressImg, int x, int y, float alpha) throws IORuntimeException
srcStream - 源图像流destStream - 目标图像流pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static void pressImage(Image srcImage, File outFile, Image pressImg, int x, int y, float alpha) throws IORuntimeException
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源outFile - 写出文件pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static void pressImage(Image srcImage, OutputStream out, Image pressImg, int x, int y, float alpha) throws IORuntimeException
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源out - 目标图像流pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static void pressImage(Image srcImage, ImageOutputStream destImageStream, Image pressImg, int x, int y, float alpha) throws IORuntimeException
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源destImageStream - 目标图像流pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException - IO异常public static Image pressImage(Image srcImage, Image pressImg, int x, int y, float alpha)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static Image pressImage(Image srcImage, Image pressImg, Rectangle rectangle, float alpha)
srcImage - 源图像流,使用结束后需手动调用flush(Image)释放资源pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件rectangle - 矩形对象,表示矩形区域的x,y,width,height,x,y从背景图片中心计算alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void rotate(File imageFile, int degree, File outFile) throws IORuntimeException
imageFile - 被旋转图像文件degree - 旋转角度outFile - 输出文件IORuntimeException - IO异常public static void rotate(Image image, int degree, File outFile) throws IORuntimeException
image - 目标图像,使用结束后需手动调用flush(Image)释放资源degree - 旋转角度outFile - 输出文件IORuntimeException - IO异常public static void rotate(Image image, int degree, OutputStream out) throws IORuntimeException
image - 目标图像,使用结束后需手动调用flush(Image)释放资源degree - 旋转角度out - 输出流IORuntimeException - IO异常public static void rotate(Image image, int degree, ImageOutputStream out) throws IORuntimeException
image - 图像,使用结束后需手动调用flush(Image)释放资源degree - 旋转角度out - 输出图像流IORuntimeException - IO异常public static Image rotate(Image image, int degree)
image - 图像,使用结束后需手动调用flush(Image)释放资源degree - 旋转角度public static void flip(File imageFile, File outFile) throws IORuntimeException
imageFile - 图像文件outFile - 输出文件IORuntimeException - IO异常public static void flip(Image image, File outFile) throws IORuntimeException
image - 图像,使用结束后需手动调用flush(Image)释放资源outFile - 输出文件IORuntimeException - IO异常public static void flip(Image image, OutputStream out) throws IORuntimeException
image - 图像,使用结束后需手动调用flush(Image)释放资源out - 输出IORuntimeException - IO异常public static void flip(Image image, ImageOutputStream out) throws IORuntimeException
image - 图像,使用结束后需手动调用flush(Image)释放资源out - 输出IORuntimeException - IO异常public static Image flip(Image image)
image - 图像,使用结束后需手动调用flush(Image)释放资源public static void compress(File imageFile, File outFile, float quality) throws IORuntimeException
imageFile - 图像文件outFile - 输出文件,只支持jpg文件quality - 压缩比例,必须为0~1IORuntimeException - IO异常@Deprecated public static RenderedImage toRenderedImage(Image img)
castToRenderedImage(Image, String)img - ImageBufferedImage@Deprecated public static BufferedImage toBufferedImage(Image img)
castToBufferedImage(Image, String)img - ImageBufferedImagepublic static RenderedImage castToRenderedImage(Image img, String imageType)
img - ImageimageType - 目标图片类型,例如jpg或png等BufferedImagepublic static BufferedImage castToBufferedImage(Image img, String imageType)
img - ImageimageType - 目标图片类型,例如jpg或png等BufferedImagepublic static BufferedImage toBufferedImage(Image image, String imageType)
Image 转 BufferedImageBufferedImage.TYPE_INT_ARGB模式,其它使用 BufferedImage.TYPE_INT_RGB 模式image - ImageimageType - 目标图片类型,例如jpg或png等BufferedImagepublic static BufferedImage toBufferedImage(Image image, String imageType, Color backgroundColor)
Image 转 BufferedImageBufferedImage.TYPE_INT_ARGB模式,其它使用 BufferedImage.TYPE_INT_RGB 模式image - ImageimageType - 目标图片类型,例如jpg或png等backgroundColor - 背景色ColorBufferedImagepublic static BufferedImage toBufferedImage(Image image, int imageType)
image - ImageimageType - 目标图片类型,BufferedImage中的常量,例如黑白等BufferedImagepublic static BufferedImage toBufferedImage(Image image, int imageType, Color backgroundColor)
image - ImageimageType - 目标图片类型,BufferedImage中的常量,例如黑白等backgroundColor - 背景色ColorBufferedImagepublic static BufferedImage copyImage(Image img, int imageType)
img - ImageimageType - 目标图片类型,BufferedImage中的常量,例如黑白等BufferedImageBufferedImage.TYPE_INT_RGB,
BufferedImage.TYPE_INT_ARGB,
BufferedImage.TYPE_INT_ARGB_PRE,
BufferedImage.TYPE_INT_BGR,
BufferedImage.TYPE_3BYTE_BGR,
BufferedImage.TYPE_4BYTE_ABGR,
BufferedImage.TYPE_4BYTE_ABGR_PRE,
BufferedImage.TYPE_BYTE_GRAY,
BufferedImage.TYPE_USHORT_GRAY,
BufferedImage.TYPE_BYTE_BINARY,
BufferedImage.TYPE_BYTE_INDEXED,
BufferedImage.TYPE_USHORT_565_RGB,
BufferedImage.TYPE_USHORT_555_RGBpublic static BufferedImage copyImage(Image img, int imageType, Color backgroundColor)
img - ImageimageType - 目标图片类型,BufferedImage中的常量,例如黑白等backgroundColor - 背景色,null 表示默认背景色(黑色或者透明)BufferedImageBufferedImage.TYPE_INT_RGB,
BufferedImage.TYPE_INT_ARGB,
BufferedImage.TYPE_INT_ARGB_PRE,
BufferedImage.TYPE_INT_BGR,
BufferedImage.TYPE_3BYTE_BGR,
BufferedImage.TYPE_4BYTE_ABGR,
BufferedImage.TYPE_4BYTE_ABGR_PRE,
BufferedImage.TYPE_BYTE_GRAY,
BufferedImage.TYPE_USHORT_GRAY,
BufferedImage.TYPE_BYTE_BINARY,
BufferedImage.TYPE_BYTE_INDEXED,
BufferedImage.TYPE_USHORT_565_RGB,
BufferedImage.TYPE_USHORT_555_RGBpublic static BufferedImage createCompatibleImage(int width, int height, int transparency) throws HeadlessException
BufferedImagewidth - 宽度height - 高度transparency - 透明模式,见 TransparencyBufferedImageHeadlessExceptionpublic static BufferedImage toImage(String base64) throws IORuntimeException
BufferedImagebase64 - 图像的Base64表示BufferedImageIORuntimeException - IO异常public static BufferedImage toImage(byte[] imageBytes) throws IORuntimeException
BufferedImageimageBytes - 图像bytesBufferedImageIORuntimeException - IO异常public static ByteArrayInputStream toStream(Image image, String imageType)
image - 图片对象imageType - 图片类型public static String toBase64DataUri(Image image, String imageType)
image - 图片对象imageType - 图片类型public static String toBase64(Image image, String imageType)
image - 图片对象imageType - 图片类型public static byte[] toBytes(Image image, String imageType)
image - 图片对象imageType - 图片类型public static void createImage(String str, Font font, Color backgroundColor, Color fontColor, ImageOutputStream out) throws IORuntimeException
str - 文字font - 字体FontbackgroundColor - 背景颜色,默认透明fontColor - 字体颜色,默认黑色out - 图片输出地IORuntimeException - IO异常public static void createTransparentImage(String str, Font font, Color fontColor, ImageOutputStream out) throws IORuntimeException
str - 文字font - 字体FontfontColor - 字体颜色,默认黑色out - 图片输出地IORuntimeException - IO异常public static BufferedImage createImage(String str, Font font, Color backgroundColor, Color fontColor, int imageType) throws IORuntimeException
str - 文字font - 字体FontbackgroundColor - 背景颜色,默认透明fontColor - 字体颜色,默认黑色imageType - 图片类型,见:BufferedImageIORuntimeException - IO异常public static Rectangle2D getRectangle(String str, Font font)
str - 字符串,必须非空font - 字体,必须非空Rectangle2Dpublic static Font createFont(File fontFile)
fontFile - 字体文件Fontpublic static Font createFont(InputStream fontStream)
fontStream - 字体流Fontpublic static Graphics2D createGraphics(BufferedImage image, Color color)
image - BufferedImagecolor - Color背景颜色以及当前画笔颜色Graphics2DGraphicsUtil.createGraphics(BufferedImage, Color)public static void writeJpg(Image image, ImageOutputStream destImageStream) throws IORuntimeException
image - ImagedestImageStream - 写出到的目标流IORuntimeException - IO异常public static void writePng(Image image, ImageOutputStream destImageStream) throws IORuntimeException
image - ImagedestImageStream - 写出到的目标流IORuntimeException - IO异常public static void writeJpg(Image image, OutputStream out) throws IORuntimeException
image - Imageout - 写出到的目标流IORuntimeException - IO异常public static void writePng(Image image, OutputStream out) throws IORuntimeException
image - Imageout - 写出到的目标流IORuntimeException - IO异常public static void write(ImageInputStream srcStream, String formatName, ImageOutputStream destStream)
srcStream - 源图像流formatName - 包含格式非正式名称的 String:如JPG、JPEG、GIF等destStream - 目标图像输出流public static void write(Image image, String imageType, OutputStream out) throws IORuntimeException
image - ImageimageType - 图片类型(图片扩展名)out - 写出到的目标流IORuntimeException - IO异常public static boolean write(Image image, String imageType, ImageOutputStream destImageStream) throws IORuntimeException
image - ImageimageType - 图片类型(图片扩展名)destImageStream - 写出到的目标流IORuntimeException - IO异常public static boolean write(Image image, String imageType, ImageOutputStream destImageStream, float quality) throws IORuntimeException
image - ImageimageType - 图片类型(图片扩展名)destImageStream - 写出到的目标流quality - 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩IORuntimeException - IO异常public static boolean write(Image image, String imageType, ImageOutputStream destImageStream, float quality, Color backgroundColor) throws IORuntimeException
image - ImageimageType - 图片类型(图片扩展名)destImageStream - 写出到的目标流quality - 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩backgroundColor - 背景色ColorIORuntimeException - IO异常public static void write(Image image, File targetFile) throws IORuntimeException
image - ImagetargetFile - 目标文件IORuntimeException - IO异常public static boolean write(Image image, ImageWriter writer, ImageOutputStream output, float quality)
ImageWriter写出图片到输出流image - 图片writer - ImageWriteroutput - 输出的Image流ImageOutputStreamquality - 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩public static ImageReader getReader(String type)
type - 图片文件类型,例如 "jpeg" 或 "tiff"ImageReaderpublic static BufferedImage read(String imageFilePath)
imageFilePath - 图片文件路径public static BufferedImage read(File imageFile)
imageFile - 图片文件public static Image getImage(URL url)
url - URLImagepublic static BufferedImage read(Resource resource)
Resource中读取图片resource - 图片资源public static BufferedImage read(InputStream imageStream)
imageStream - 图片文件public static BufferedImage read(ImageInputStream imageStream)
imageStream - 图片文件public static BufferedImage read(URL imageUrl)
imageUrl - 图片文件public static ImageOutputStream getImageOutputStream(OutputStream out) throws IORuntimeException
out - OutputStreamImageOutputStreamIORuntimeException - IO异常public static ImageOutputStream getImageOutputStream(File outFile) throws IORuntimeException
outFile - FileImageOutputStreamIORuntimeException - IO异常public static ImageInputStream getImageInputStream(InputStream in) throws IORuntimeException
in - InputStreamImageInputStreamIORuntimeException - IO异常public static ImageWriter getWriter(Image img, String formatName)
ImageWriter,如果未找到合适的Writer,返回nullimg - ImageformatName - 图片格式,例如"jpg"、"png"ImageWriterpublic static ImageWriter getWriter(String formatName)
ImageWriter,如果未找到合适的Writer,返回nullformatName - 图片格式或扩展名,例如"jpg"、"png"ImageWriterpublic static String toHex(Color color)
color - ColorColorUtil.toHex(Color)public static String toHex(int r, int g, int b)
r - 红(R)g - 绿(G)b - 蓝(B)ColorUtil.toHex(int, int, int)public static Color hexToColor(String hex)
hex - 16进制的颜色值,例如#fcf6d6Colorpublic static Color getColor(int rgb)
rgb - RGB值ColorColorUtil.getColor(int)public static Color getColor(String colorName)
1. 颜色的英文名(大小写皆可) 2. 16进制表示,例如:#fcf6d6或者$fcf6d6 3. RGB形式,例如:13,148,252
方法来自:com.lnwazg.kit
colorName - 颜色的英文名,16进制表示或RGB表示ColorColorUtil.getColor(String)public static Color randomColor()
ColorUtil.randomColor()public static Color randomColor(Color compareColor, int minDistance)
compareColor - 比较颜色minDistance - 最小色差,按三维坐标计算的距离值public static Color randomColor(Color compareColor)
compareColor - 比较颜色public static Color randomColor(Random random)
random - 随机对象 RandomColorUtil.randomColor(Random)public static Point getPointBaseCentre(Rectangle rectangle, int backgroundWidth, int backgroundHeight)
rectangle - 矩形backgroundWidth - 参考宽(背景宽)backgroundHeight - 参考高(背景高)Pointpublic static String getMainColor(BufferedImage image, int[]... rgbFilters)
image - BufferedImagergbFilters - 过滤多种颜色String #ffffffpublic static boolean backgroundRemoval(String inputPath, String outputPath, int tolerance)
inputPath - 要处理图片的路径outputPath - 输出图片的路径tolerance - 容差值[根据图片的主题色,加入容差值,值的范围在0~255之间]public static boolean backgroundRemoval(File input, File output, int tolerance)
input - 需要进行操作的图片output - 最后输出的文件tolerance - 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]public static boolean backgroundRemoval(File input, File output, Color override, int tolerance)
input - 需要进行操作的图片output - 最后输出的文件override - 指定替换成的背景颜色 为null时背景为透明tolerance - 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]public static BufferedImage backgroundRemoval(BufferedImage bufferedImage, Color override, int tolerance)
bufferedImage - 需要进行处理的图片流override - 指定替换成的背景颜色 为null时背景为透明tolerance - 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]public static BufferedImage backgroundRemoval(ByteArrayOutputStream outputStream, Color override, int tolerance)
outputStream - 需要进行处理的图片字节数组流override - 指定替换成的背景颜色 为null时背景为透明tolerance - 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]public static BufferedImage colorConvert(ColorSpace colorSpace, BufferedImage image)
colorSpace - 颜色模式,如灰度等image - 被转换的图片public static BufferedImage transform(AffineTransform xform, BufferedImage image)
xform - 2D仿射变换,它执行从 2D 坐标到其他 2D 坐标的线性映射,保留了线的“直线性”和“平行性”。image - 被转换的图片public static BufferedImage filter(BufferedImageOp op, BufferedImage image)
op - 过滤操作实现,如二维转换可传入AffineTransformOpimage - 原始图片public static Image filter(ImageFilter filter, Image image)
ImageFilter实现,实现不同的图片滤镜filter - 滤镜实现image - 图片Copyright © 2025. All rights reserved.