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 void |
backgroundRemoval(File input,
File output,
Color override,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static void |
backgroundRemoval(File input,
File output,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static void |
backgroundRemoval(String inputPath,
String outputPath,
int tolerance)
背景移除
图片去底工具
将 "纯色背景的图片" 还原成 "透明背景的图片"
将纯色背景的图片转成矢量图
取图片边缘的像素点和获取到的图片主题色作为要替换的背景色
再加入一定的容差值,然后将所有像素点与该颜色进行比较
发现相同则将颜色不透明度设置为0,使颜色完全透明.
|
static void |
binary(File srcImageFile,
File targetImageFile)
彩色转为黑白二值化图片,根据目标文件扩展名确定转换后的格式
|
static Image |
binary(Image srcImage)
彩色转为黑白二值化图片
|
static void |
binary(Image srcImage,
File outFile)
彩色转为黑白二值化图片,根据目标文件扩展名确定转换后的格式
|
static void |
binary(Image srcImage,
ImageOutputStream targetImageStream,
String imageType)
彩色转为黑白二值化图片
此方法并不关闭流,输出JPG格式 |
static void |
binary(ImageInputStream srcStream,
ImageOutputStream targetStream,
String imageType)
彩色转为黑白黑白二值化图片
此方法并不关闭流 |
static void |
binary(Image srcImage,
OutputStream out,
String imageType)
彩色转为黑白二值化图片
此方法并不关闭流,输出JPG格式 |
static void |
binary(InputStream srcStream,
OutputStream targetStream,
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 targetImageFile)
图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
|
static void |
convert(Image srcImage,
String formatName,
ImageOutputStream targetImageStream)
图像类型转换:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static void |
convert(InputStream srcStream,
String formatName,
OutputStream targetStream)
图像类型转换: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 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 targetImgFile,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割)
|
static void |
cut(Image srcImage,
File destFile,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static void |
cut(Image srcImage,
ImageOutputStream targetImageStream,
Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割),此方法并不关闭流
|
static void |
cut(ImageInputStream srcStream,
ImageOutputStream targetStream,
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 targetStream,
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 Image |
getImage(URL url)
从URL中获取或读取图片对象
|
static ImageInputStream |
getImageInputStream(InputStream in)
|
static ImageOutputStream |
getImageOutputStream(File outFile)
|
static ImageOutputStream |
getImageOutputStream(OutputStream out)
|
static Point |
getPointBaseCentre(Rectangle rectangle,
int backgroundWidth,
int backgroundHeight)
获得修正后的矩形坐标位置,变为以背景中心为基准坐标(即x,y == 0,0时,处于背景正中)
|
static ImageReader |
getReader(String type)
|
static Pair<Integer,Integer> |
getWidthAndHeight(ImageInputStream imageStream,
String type)
通过
ImageInputStream 获取对应类型的宽和高 |
static Pair<Integer,Integer> |
getWidthAndHeight(InputStream imageStream,
String type)
通过
ImageInputStream 获取对应类型的宽和高 |
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 targetImageFile)
彩色转为黑白
|
static Image |
gray(Image srcImage)
彩色转为黑白
|
static void |
gray(Image srcImage,
File outFile)
彩色转为黑白
|
static void |
gray(Image srcImage,
ImageOutputStream targetImageStream)
彩色转为黑白
此方法并不关闭流 |
static void |
gray(ImageInputStream srcStream,
ImageOutputStream targetStream)
彩色转为黑白
此方法并不关闭流 |
static void |
gray(Image srcImage,
OutputStream out)
彩色转为黑白
此方法并不关闭流 |
static void |
gray(InputStream srcStream,
OutputStream targetStream)
彩色转为黑白
此方法并不关闭流 |
static void |
pressImage(File srcImageFile,
File targetImageFile,
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 targetImageStream,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印,写出目标图片格式为JPG
此方法并不关闭流 |
static Image |
pressImage(Image srcImage,
Image pressImg,
Rectangle rectangle,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressImage(Image srcImage,
OutputStream out,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印,写出目标图片格式为JPG
此方法并不关闭流 |
static void |
pressImage(InputStream srcStream,
OutputStream targetStream,
Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
static void |
pressImageFull(File imageFile,
File targetFile,
File pressImageFile,
int lineHeight,
int degree,
float alpha)
给图片添加全屏图片水印
|
static Image |
pressImageFull(Image srcImage,
Image pressImage,
int lineHeight,
int degree,
float alpha)
给图片添加全屏图像水印
此方法并不关闭流 |
static void |
pressImageFull(InputStream srcStream,
OutputStream targetStream,
InputStream pressStream,
int lineHeight,
int degree,
float alpha)
给图片添加全屏图像水印,写出格式为JPG
此方法并不关闭流 |
static void |
pressText(File imageFile,
File targetFile,
DisplayText pressText)
给图片添加文字水印
|
static Image |
pressText(Image srcImage,
DisplayText pressText)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(Image srcImage,
File targetFile,
DisplayText pressText)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(Image srcImage,
ImageOutputStream targetImageStream,
DisplayText pressText)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(Image srcImage,
OutputStream to,
DisplayText pressText)
给图片添加文字水印
此方法并不关闭流 |
static void |
pressText(InputStream srcStream,
OutputStream targetStream,
DisplayText pressText)
给图片添加文字水印
此方法并不关闭流 |
static Image |
pressTextFull(Image srcImage,
String pressText,
Color color,
Font font,
int lineHeight,
int degree,
float alpha)
给图片添加全屏文字水印
此方法并不关闭流 |
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 targetImageFile,
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 targetImageStream,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(ImageInputStream srcStream,
ImageOutputStream targetStream,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(ImageInputStream srcStream,
ImageOutputStream targetStream,
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 targetStream,
float scale)
缩放图像(按比例缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
scale(InputStream srcStream,
OutputStream targetStream,
int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式,此方法并不关闭流 |
static void |
slice(File srcImageFile,
File descDir,
int targetWidth,
int targetHeight)
图像切片(指定切片的宽度和高度)
|
static void |
slice(Image srcImage,
File descDir,
int targetWidth,
int targetHeight)
图像切片(指定切片的宽度和高度)
|
static void |
sliceByRowsAndCols(File srcImageFile,
File targetDir,
String formatName,
int rows,
int cols)
图像切割(指定切片的行数和列数)
|
static void |
sliceByRowsAndCols(Image srcImage,
File destDir,
String formatName,
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 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 BufferedImage |
toImage(byte[] imageBytes)
将的图像bytes转为
BufferedImage |
static BufferedImage |
toImage(String base64)
将Base64编码的图像信息转为
BufferedImage |
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 void |
write(ImageInputStream srcStream,
String formatName,
ImageOutputStream targetStream)
按照目标格式写出图像:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static void |
write(Image image,
String imageType,
ImageOutputStream targetImageStream)
写出图像为指定格式:GIF=》JPG、GIF=》PNG、PNG=》JPG、PNG=》GIF(X)、BMP=》PNG
此方法并不关闭流 |
static void |
write(Image image,
String imageType,
ImageOutputStream output,
float quality)
通过
ImageWriter 写出图片到输出流 |
static void |
write(Image image,
String imageType,
ImageOutputStream out,
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 targetImageStream)
写出图像为JPG格式
|
static void |
writeJpg(Image image,
OutputStream out)
写出图像为JPG格式
|
static void |
writePng(Image image,
ImageOutputStream targetImageStream)
写出图像为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 targetStream, float scale)
srcStream
- 源图像来源流targetStream
- 缩放后的图像写出到的流scale
- 缩放比例。比例大于1时为放大,小于1大于0为缩小public static void scale(ImageInputStream srcStream, ImageOutputStream targetStream, float scale)
srcStream
- 源图像来源流targetStream
- 缩放后的图像写出到的流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为缩小Image
public static Image scale(Image srcImg, int width, int height)
srcImg
- 源图像来源流,使用结束后需手动调用flush(Image)
释放资源width
- 目标宽度height
- 目标高度Image
public static void scale(File srcImageFile, File targetImageFile, int width, int height, Color fixedColor) throws IORuntimeException
srcImageFile
- 源图像文件地址targetImageFile
- 缩放后的图像地址width
- 缩放后的宽度height
- 缩放后的高度fixedColor
- 补充的颜色,不补充为null
IORuntimeException
- IO异常public static void scale(InputStream srcStream, OutputStream targetStream, int width, int height, Color fixedColor) throws IORuntimeException
srcStream
- 源图像流targetStream
- 缩放后的图像目标流width
- 缩放后的宽度height
- 缩放后的高度fixedColor
- 比例不对时补充的颜色,不补充为null
IORuntimeException
- IO异常public static void scale(ImageInputStream srcStream, ImageOutputStream targetStream, int width, int height, Color fixedColor) throws IORuntimeException
srcStream
- 源图像流targetStream
- 缩放后的图像目标流width
- 缩放后的宽度height
- 缩放后的高度fixedColor
- 比例不对时补充的颜色,不补充为null
IORuntimeException
- IO异常public static void scale(Image srcImage, ImageOutputStream targetImageStream, int width, int height, Color fixedColor) throws IORuntimeException
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 缩放后的图像目标流width
- 缩放后的宽度height
- 缩放后的高度fixedColor
- 比例不对时补充的颜色,不补充为null
IORuntimeException
- IO异常public static Image scale(Image srcImage, int width, int height, Color fixedColor)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源width
- 缩放后的宽度height
- 缩放后的高度fixedColor
- 比例不对时补充的颜色,不补充为null
Image
public static void cut(File srcImgFile, File targetImgFile, Rectangle rectangle)
srcImgFile
- 源图像文件targetImgFile
- 切片后的图像文件rectangle
- 矩形对象,表示矩形区域的x,y,width,heightpublic static void cut(InputStream srcStream, OutputStream targetStream, Rectangle rectangle)
srcStream
- 源图像流targetStream
- 切片后的图像输出流rectangle
- 矩形对象,表示矩形区域的x,y,width,heightpublic static void cut(ImageInputStream srcStream, ImageOutputStream targetStream, Rectangle rectangle)
srcStream
- 源图像流targetStream
- 切片后的图像输出流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
- 源图像out
- 切片后的图像输出流rectangle
- 矩形对象,表示矩形区域的x,y,width,heightIORuntimeException
- IO异常public static void cut(Image srcImage, ImageOutputStream targetImageStream, Rectangle rectangle) throws IORuntimeException
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 切片后的图像输出流rectangle
- 矩形对象,表示矩形区域的x,y,width,heightIORuntimeException
- IO异常public static Image cut(Image srcImage, Rectangle rectangle)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源rectangle
- 矩形对象,表示矩形区域的x,y,width,heightBufferedImage
public static Image cut(Image srcImage, int x, int y)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源x
- 原图的x坐标起始位置y
- 原图的y坐标起始位置Image
public static Image cut(Image srcImage, int x, int y, int radius)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源x
- 原图的x坐标起始位置y
- 原图的y坐标起始位置radius
- 半径,小于0表示填充满整个图片(直径取长宽最小值)Image
public static void slice(File srcImageFile, File descDir, int targetWidth, int targetHeight)
srcImageFile
- 源图像descDir
- 切片目标文件夹targetWidth
- 目标切片宽度。默认200targetHeight
- 目标切片高度。默认150public static void slice(Image srcImage, File descDir, int targetWidth, int targetHeight)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源descDir
- 切片目标文件夹targetWidth
- 目标切片宽度。默认200targetHeight
- 目标切片高度。默认150public static void sliceByRowsAndCols(File srcImageFile, File targetDir, String formatName, int rows, int cols)
srcImageFile
- 源图像文件targetDir
- 切片目标文件夹formatName
- 格式名称,即图片格式后缀rows
- 目标切片行数。默认2,必须是范围 [1, 20] 之内cols
- 目标切片列数。默认2,必须是范围 [1, 20] 之内public static void sliceByRowsAndCols(Image srcImage, File destDir, String formatName, int rows, int cols)
srcImage
- 源图像,如果非BufferedImage
,则默认使用RGB模式,使用结束后需手动调用flush(Image)
释放资源destDir
- 切片目标文件夹formatName
- 格式名称,即图片格式后缀rows
- 目标切片行数。默认2,必须是范围 [1, 20] 之内cols
- 目标切片列数。默认2,必须是范围 [1, 20] 之内public static void convert(File srcImageFile, File targetImageFile)
srcImageFile
- 源图像文件targetImageFile
- 目标图像文件public static void convert(InputStream srcStream, String formatName, OutputStream targetStream)
srcStream
- 源图像流formatName
- 包含格式非正式名称的 String:如JPG、JPEG、GIF等targetStream
- 目标图像输出流public static void convert(Image srcImage, String formatName, ImageOutputStream targetImageStream)
srcImage
- 源图像流,使用结束后需手动调用flush(Image)
释放资源formatName
- 包含格式非正式名称的 String:如JPG、JPEG、GIF等targetImageStream
- 目标图像输出流public static void gray(File srcImageFile, File targetImageFile)
srcImageFile
- 源图像地址targetImageFile
- 目标图像地址public static void gray(InputStream srcStream, OutputStream targetStream)
srcStream
- 源图像流targetStream
- 目标图像流public static void gray(ImageInputStream srcStream, ImageOutputStream targetStream)
srcStream
- 源图像流targetStream
- 目标图像流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 targetImageStream) throws IORuntimeException
srcImage
- 源图像流,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 目标图像流IORuntimeException
- IO异常public static Image gray(Image srcImage)
srcImage
- 源图像流,使用结束后需手动调用flush(Image)
释放资源Image
灰度后的图片public static void binary(File srcImageFile, File targetImageFile)
srcImageFile
- 源图像地址targetImageFile
- 目标图像地址public static void binary(InputStream srcStream, OutputStream targetStream, String imageType)
srcStream
- 源图像流targetStream
- 目标图像流imageType
- 图片格式(扩展名)public static void binary(ImageInputStream srcStream, ImageOutputStream targetStream, String imageType)
srcStream
- 源图像流targetStream
- 目标图像流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 targetImageStream, String imageType) throws IORuntimeException
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 目标图像流imageType
- 图片格式(扩展名)IORuntimeException
- IO异常public static Image binary(Image srcImage)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源Image
二值化后的图片public static void pressText(File imageFile, File targetFile, DisplayText pressText)
imageFile
- 源图像文件targetFile
- 目标图像文件pressText
- 水印文字public static void pressText(InputStream srcStream, OutputStream targetStream, DisplayText pressText)
srcStream
- 源图像流targetStream
- 目标图像流pressText
- 水印文本信息public static void pressText(Image srcImage, File targetFile, DisplayText pressText) throws IORuntimeException
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源targetFile
- 目标流pressText
- 水印文字信息IORuntimeException
- IO异常public static void pressText(Image srcImage, OutputStream to, DisplayText pressText) throws IORuntimeException
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源to
- 目标流pressText
- 水印文字信息IORuntimeException
- IO异常public static void pressText(Image srcImage, ImageOutputStream targetImageStream, DisplayText pressText) throws IORuntimeException
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 目标图像流pressText
- 水印文字信息IORuntimeException
- IO异常public static Image pressText(Image srcImage, DisplayText pressText)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源pressText
- 水印文字信息public static Image pressTextFull(Image srcImage, String pressText, Color color, Font font, int lineHeight, int degree, float alpha)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源pressText
- 水印文字color
- 水印的字体颜色font
- Font
字体相关信息,如果默认则为null
lineHeight
- 行高degree
- 旋转角度,(单位:弧度),以圆点(0,0)为圆心,正代表顺时针,负代表逆时针alpha
- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressImage(File srcImageFile, File targetImageFile, Image pressImg, int x, int y, float alpha)
srcImageFile
- 源图像文件targetImageFile
- 目标图像文件pressImg
- 水印图片,使用结束后需手动调用flush(Image)
释放资源x
- 修正值。 默认在中间,偏移量相对于中间偏移y
- 修正值。 默认在中间,偏移量相对于中间偏移alpha
- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public static void pressImage(InputStream srcStream, OutputStream targetStream, Image pressImg, int x, int y, float alpha)
srcStream
- 源图像流targetStream
- 目标图像流pressImg
- 水印图片,可以使用ImageIO.read(File)
方法读取文件x
- 修正值。 默认在中间,偏移量相对于中间偏移y
- 修正值。 默认在中间,偏移量相对于中间偏移alpha
- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字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 targetImageStream, Image pressImg, int x, int y, float alpha) throws IORuntimeException
srcImage
- 源图像流,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 目标图像流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 pressImageFull(File imageFile, File targetFile, File pressImageFile, int lineHeight, int degree, float alpha) throws IORuntimeException
imageFile
- 源图像文件targetFile
- 目标图像文件pressImageFile
- 水印图像文件lineHeight
- 行高degree
- 水印图像旋转角度,(单位:弧度),以圆点(0,0)为圆心,正代表顺时针,负代表逆时针alpha
- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException
- IO异常public static void pressImageFull(InputStream srcStream, OutputStream targetStream, InputStream pressStream, int lineHeight, int degree, float alpha) throws IORuntimeException
srcStream
- 源图像流targetStream
- 目标图像流pressStream
- 水印图像流lineHeight
- 行高degree
- 水印图像旋转角度,(单位:弧度),以圆点(0,0)为圆心,正代表顺时针,负代表逆时针alpha
- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字IORuntimeException
- IO异常public static Image pressImageFull(Image srcImage, Image pressImage, int lineHeight, int degree, float alpha)
srcImage
- 源图像,使用结束后需手动调用flush(Image)
释放资源pressImage
- 水印图像,使用结束后需手动调用flush(Image)
释放资源lineHeight
- 行高degree
- 水印图像旋转角度,(单位:弧度),以圆点(0,0)为圆心,正代表顺时针,负代表逆时针,(单位:弧度),以圆点(0,0)为圆心,正代表顺时针,负代表逆时针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异常public static RenderedImage castToRenderedImage(Image img, String imageType)
img
- Image
imageType
- 目标图片类型,例如jpg或png等BufferedImage
public static BufferedImage castToBufferedImage(Image img, String imageType)
img
- Image
imageType
- 目标图片类型,例如jpg或png等BufferedImage
public static BufferedImage toBufferedImage(Image image, String imageType)
Image
转 BufferedImage
BufferedImage.TYPE_INT_ARGB
模式,其它使用 BufferedImage.TYPE_INT_RGB
模式image
- Image
imageType
- 目标图片类型,例如jpg或png等BufferedImage
public static BufferedImage toBufferedImage(Image image, String imageType, Color backgroundColor)
Image
转 BufferedImage
BufferedImage.TYPE_INT_ARGB
模式,其它使用 BufferedImage.TYPE_INT_RGB
模式image
- Image
imageType
- 目标图片类型,例如jpg或png等backgroundColor
- 背景色Color
,null
表示默认背景色(黑色或者透明)BufferedImage
public static BufferedImage toBufferedImage(Image image, int imageType)
image
- Image
imageType
- 目标图片类型,BufferedImage
中的常量,例如黑白等BufferedImage
public static BufferedImage toBufferedImage(Image image, int imageType, Color backgroundColor)
image
- Image
imageType
- 目标图片类型,BufferedImage
中的常量,例如黑白等backgroundColor
- 背景色Color
,null
表示默认背景色(黑色或者透明)BufferedImage
public static BufferedImage copyImage(Image img, int imageType)
img
- Image
imageType
- 目标图片类型,BufferedImage
中的常量,例如黑白等BufferedImage
BufferedImage.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_RGB
public static BufferedImage copyImage(Image img, int imageType, Color backgroundColor)
img
- Image
imageType
- 目标图片类型,BufferedImage
中的常量,例如黑白等backgroundColor
- 背景色,null
表示默认背景色(黑色或者透明)BufferedImage
BufferedImage.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_RGB
public static BufferedImage toImage(String base64) throws IORuntimeException
BufferedImage
base64
- 图像的Base64表示BufferedImage
IORuntimeException
- IO异常public static BufferedImage toImage(byte[] imageBytes) throws IORuntimeException
BufferedImage
imageBytes
- 图像bytesBufferedImage
IORuntimeException
- 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 BufferedImage createCompatibleImage(int width, int height, int transparency)
BufferedImage
width
- 宽度height
- 高度transparency
- 透明模式,见 Transparency
BufferedImage
public static void createTransparentImage(String str, Font font, Color fontColor, ImageOutputStream out) throws IORuntimeException
str
- 文字font
- 字体Font
fontColor
- 字体颜色,默认黑色out
- 图片输出地IORuntimeException
- IO异常public static void createImage(String str, Font font, Color backgroundColor, Color fontColor, ImageOutputStream out) throws IORuntimeException
str
- 文字font
- 字体Font
backgroundColor
- 背景颜色,默认透明fontColor
- 字体颜色,默认黑色out
- 图片输出地IORuntimeException
- IO异常public static BufferedImage createImage(String str, Font font, Color backgroundColor, Color fontColor, int imageType) throws IORuntimeException
str
- 文字font
- 字体Font
backgroundColor
- 背景颜色,默认透明fontColor
- 字体颜色,默认黑色imageType
- 图片类型,见:BufferedImage
IORuntimeException
- IO异常public static void writeJpg(Image image, ImageOutputStream targetImageStream) throws IORuntimeException
image
- Image
targetImageStream
- 写出到的目标流IORuntimeException
- IO异常public static void writePng(Image image, ImageOutputStream targetImageStream) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源targetImageStream
- 写出到的目标流IORuntimeException
- IO异常public static void writeJpg(Image image, OutputStream out) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源out
- 写出到的目标流IORuntimeException
- IO异常public static void writePng(Image image, OutputStream out) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源out
- 写出到的目标流IORuntimeException
- IO异常public static void write(ImageInputStream srcStream, String formatName, ImageOutputStream targetStream)
srcStream
- 源图像流formatName
- 包含格式非正式名称的 String:如JPG、JPEG、GIF等targetStream
- 目标图像输出流public static void write(Image image, String imageType, OutputStream out) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源imageType
- 图片类型(图片扩展名)out
- 写出到的目标流IORuntimeException
- IO异常public static void write(Image image, File targetFile) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源targetFile
- 目标文件IORuntimeException
- IO异常public static void write(Image image, String imageType, ImageOutputStream targetImageStream) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源imageType
- 图片类型(图片扩展名)targetImageStream
- 写出到的目标流IORuntimeException
- IO异常public static void write(Image image, String imageType, ImageOutputStream out, float quality, Color backgroundColor) throws IORuntimeException
image
- Image
,使用结束后需手动调用flush(Image)
释放资源imageType
- 图片类型(图片扩展名),null
表示使用RGB模式(JPG)out
- 写出到的目标流quality
- 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩backgroundColor
- 背景色Color
IORuntimeException
- IO异常public static void write(Image image, String imageType, ImageOutputStream output, float quality)
ImageWriter
写出图片到输出流image
- 图片,使用结束后需手动调用flush(Image)
释放资源imageType
- 图片类型output
- 输出的Image流ImageOutputStream
quality
- 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩public static ImageWriter getWriter(Image img, String formatName)
ImageWriter
,如果未找到合适的Writer,返回nullimg
- Image
,使用结束后需手动调用flush(Image)
释放资源formatName
- 图片格式,例如"jpg"、"png",null
则使用默认值"jpg"ImageWriter
public static ImageWriter getWriter(String formatName)
ImageWriter
,如果未找到合适的Writer,返回nullformatName
- 图片格式或扩展名,例如"jpg"、"png",null
则使用默认值"jpg"ImageWriter
public static BufferedImage read(String imageFilePath)
imageFilePath
- 图片文件路径public static BufferedImage read(File imageFile)
imageFile
- 图片文件public 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 ImageReader getReader(String type)
type
- 图片文件类型,例如 "jpeg" 或 "tiff"ImageReader
public static Pair<Integer,Integer> getWidthAndHeight(InputStream imageStream, String type)
ImageInputStream
获取对应类型的宽和高imageStream
- ImageInputStream
type
- 图片类型public static Pair<Integer,Integer> getWidthAndHeight(ImageInputStream imageStream, String type)
ImageInputStream
获取对应类型的宽和高imageStream
- ImageInputStream
type
- 图片类型public static Image getImage(URL url)
url
- URLImage
public static ImageOutputStream getImageOutputStream(OutputStream out) throws IORuntimeException
out
- OutputStream
ImageOutputStream
IORuntimeException
- IO异常public static ImageOutputStream getImageOutputStream(File outFile) throws IORuntimeException
outFile
- File
ImageOutputStream
IORuntimeException
- IO异常public static ImageInputStream getImageInputStream(InputStream in) throws IORuntimeException
in
- InputStream
ImageInputStream
IORuntimeException
- IO异常public static Point getPointBaseCentre(Rectangle rectangle, int backgroundWidth, int backgroundHeight)
rectangle
- 矩形backgroundWidth
- 参考宽(背景宽)backgroundHeight
- 参考高(背景高)Point
public static void backgroundRemoval(String inputPath, String outputPath, int tolerance)
inputPath
- 要处理图片的路径outputPath
- 输出图片的路径tolerance
- 容差值[根据图片的主题色,加入容差值,值的范围在0~255之间]public static void backgroundRemoval(File input, File output, int tolerance)
input
- 需要进行操作的图片output
- 最后输出的文件tolerance
- 容差值[根据图片的主题色,加入容差值,值的取值范围在0~255之间]public static void 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
- 过滤操作实现,如二维转换可传入AffineTransformOp
image
- 原始图片public static Image filter(ImageFilter filter, Image image)
ImageFilter
实现,实现不同的图片滤镜filter
- 滤镜实现image
- 图片Copyright © 2025. All rights reserved.