public class Image extends Object implements Serializable
| Constructor and Description |
|---|
Image(BufferedImage srcImage)
构造
|
| Modifier and Type | Method and Description |
|---|---|
Image |
binary()
彩色转为黑白二值化图片
|
Image |
cut(int x,
int y)
图像切割为圆形(按指定起点坐标和半径切割),填充满整个图片(直径取长宽最小值)
|
Image |
cut(int x,
int y,
int radius)
图像切割为圆形(按指定起点坐标和半径切割)
|
Image |
cut(Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割)
|
Image |
flip()
水平翻转图像
|
static Image |
from(File imageFile)
从文件读取图片并开始处理
|
static Image |
from(Image image)
从Image取图片并开始处理
|
static Image |
from(ImageInputStream imageStream)
从ImageInputStream取图片并开始处理
|
static Image |
from(InputStream in)
从流读取图片并开始处理
|
static Image |
from(Path imagePath)
从Path读取图片并开始处理
|
static Image |
from(Resource resource)
从资源对象中读取图片并开始处理
|
static Image |
from(URL imageUrl)
从URL取图片并开始处理
|
Image |
getImg()
获取处理过的图片
|
Image |
gray()
彩色转为黑白
|
Image |
pressImage(Image pressImage,
int x,
int y,
float alpha)
给图片添加图片水印
|
Image |
pressImage(Image pressImage,
Rectangle rectangle,
float alpha)
给图片添加图片水印
|
Image |
pressText(String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流
|
Image |
rotate(int degree)
旋转图片为指定角度
来自:http://blog.51cto.com/cping1982/130066
|
Image |
round(double arc)
图片圆角处理
|
Image |
scale(float scale)
缩放图像(按比例缩放)
|
Image |
scale(int width,
int height)
缩放图像(按长宽缩放)
注意:目标长宽与原图不成比例会变形
|
Image |
scale(int width,
int height,
Color fixedColor)
等比缩放图像,此方法按照按照给定的长宽等比缩放图片,按照长宽缩放比最多的一边等比缩放,空白部分填充背景色
缩放后默认为jpeg格式
|
Image |
setPositionBaseCentre(boolean positionBaseCentre)
计算x,y坐标的时候是否从中心做为原始坐标开始计算
|
Image |
setQuality(double quality)
设置图片输出质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩
|
Image |
setQuality(float quality)
设置图片输出质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩
|
Image |
setTargetImageType(String imgType)
设置目标图片文件格式,用于写出
|
boolean |
write(File targetFile)
写出图像为目标文件扩展名对应的格式
|
boolean |
write(ImageOutputStream targetImageStream)
写出图像为PNG格式
|
boolean |
write(OutputStream out)
写出图像
|
public Image(BufferedImage srcImage)
srcImage - 来源图片public static Image from(Path imagePath)
imagePath - 图片文件路径Imagepublic static Image from(File imageFile)
imageFile - 图片文件Imagepublic static Image from(Resource resource)
resource - 图片资源对象Imagepublic static Image from(InputStream in)
in - 图片流Imagepublic static Image from(ImageInputStream imageStream)
imageStream - 图片流Imagepublic static Image from(URL imageUrl)
imageUrl - 图片URLImagepublic Image setTargetImageType(String imgType)
imgType - 图片格式FileType.IMAGE_TYPE_JPG,
FileType.IMAGE_TYPE_PNGpublic Image setPositionBaseCentre(boolean positionBaseCentre)
positionBaseCentre - 是否从中心做为原始坐标开始计算public Image setQuality(double quality)
quality - 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩public Image setQuality(float quality)
quality - 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩public Image scale(float scale)
scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小public Image scale(int width, int height)
width - 目标宽度height - 目标高度public Image scale(int width, int height, Color fixedColor)
width - 缩放后的宽度height - 缩放后的高度fixedColor - 比例不对时补充的颜色,不补充为nullpublic Image cut(Rectangle rectangle)
rectangle - 矩形对象,表示矩形区域的x,y,width,heightpublic Image cut(int x, int y)
x - 原图的x坐标起始位置y - 原图的y坐标起始位置public Image cut(int x, int y, int radius)
x - 原图的x坐标起始位置y - 原图的y坐标起始位置radius - 半径,小于0表示填充满整个图片(直径取长宽最小值)public Image round(double arc)
arc - 圆角弧度,0~1,为长宽占比public Image gray()
public Image binary()
public Image pressText(String pressText, Color color, Font font, int x, int y, float alpha)
pressText - 水印文字color - 水印的字体颜色font - Font 字体相关信息x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public Image pressImage(Image pressImage, int x, int y, float alpha)
pressImage - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public Image pressImage(Image pressImage, Rectangle rectangle, float alpha)
pressImage - 水印图片,可以使用ImageIO.read(File)方法读取文件rectangle - 矩形对象,表示矩形区域的x,y,width,height,x,y从背景图片中心计算alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public Image rotate(int degree)
degree - 旋转角度public Image flip()
public Image getImg()
public boolean write(OutputStream out) throws InstrumentException
out - 写出到的目标流InstrumentException - IO异常public boolean write(ImageOutputStream targetImageStream) throws InstrumentException
targetImageStream - 写出到的目标流InstrumentException - IO异常public boolean write(File targetFile) throws InstrumentException
targetFile - 目标文件InstrumentException - IO异常Copyright © 2019. All rights reserved.