Package org.aoju.bus.core.image
Class Images
java.lang.Object
org.aoju.bus.core.image.Images
-
Constructor Summary
ConstructorsConstructorDescriptionImages(BufferedImage srcImage) 构造Images(BufferedImage bgImage, int width, int height, Scale.Zoom zoomMode, String fileType) Images(BufferedImage srcImage, String fileType) 构造Images(BufferedImage srcImage, String imageUrl, String fileType) 构造:图片合成专用Images(String bgImageUrl, int width, int height, Scale.Zoom zoom, String fileType) 构造 -
Method Summary
Modifier and TypeMethodDescriptionvoidaddElement(AbstractElement element) 添加元素(图片或文本)addImageElement(BufferedImage image, int x, int y) 添加图片元素addImageElement(BufferedImage image, int x, int y, int width, int height, Scale.Zoom zoom) 添加图片元素addImageElement(String imgUrl, int x, int y) 添加图片元素addImageElement(String imgUrl, int x, int y, int width, int height, Scale.Zoom zoom) 添加图片元素addRectangleElement(int x, int y, int width, int height) 添加矩形元素addTextElement(String text, int fontSize, int x, int y) 添加文本元素addTextElement(String text, Font font, int x, int y) 添加文本元素addTextElement(String text, String fontName, int fontSize, int x, int y) 添加文本元素binary()彩色转为黑白二值化图片cut(int x, int y) 图像切割为圆形(按指定起点坐标和半径切割),填充满整个图片(直径取长宽最小值)cut(int x, int y, int radius) 图像切割为圆形(按指定起点坐标和半径切割)图像切割(按指定起点坐标和宽高切割)flip()水平翻转图像static Images从Image取图片并开始处理static Imagesfrom(BufferedImage srcImage, String imageUrl, String fileType) 图片合成专用-读取图片static Images从文件读取图片并开始处理static Imagesfrom(InputStream in) 从流读取图片并开始处理static Images从URL取图片并开始处理static Images从Path读取图片并开始处理static Imagesfrom(ImageInputStream imageStream) 从ImageInputStream取图片并开始处理static Images从资源对象中读取图片并开始处理int获取画布高度int获取画布宽度getImg()获取处理过的图片获取合成后的图片流获取合成后的图片对象gray()彩色转为灰度static BufferedImagemakeBlur(BufferedImage srcImage, int radius) 高斯模糊(毛玻璃效果)static BufferedImagemakeRoundCorner(BufferedImage srcImage, int width, int height, int radius) 圆角merge()合成图片,返回图片对象void保存合成后的图片pressImage(Image pressImage, int x, int y, float alpha) 给图片添加图片水印pressImage(Image pressImage, Rectangle rectangle, float alpha) 给图片添加图片水印给图片添加文字水印 此方法只在给定位置写出一个水印字符串给图片添加文字水印 此方法只在给定位置写出一个水印字符串pressTextFull(String pressText, Color color, Font font, int lineHeight, int degree, float alpha) 给图片添加全屏文字水印rotate(int degree) 旋转图片为指定角度 来自:http://blog.51cto.com/cping1982/130066round(double arc) 图片圆角处理scale(float scale) 缩放图像(按比例缩放)scale(int width, int height) 缩放图像(按长宽缩放) 注意:目标长宽与原图不成比例会变形scale(int width, int height, int scaleType) 缩放图像(按长宽缩放) 注意:目标长宽与原图不成比例会变形等比缩放图像,此方法按照按照给定的长宽等比缩放图片,按照长宽缩放比最多的一边等比缩放,空白部分填充背景色 缩放后默认为jpeg格式voidsetBackgroundBlur(int blur) 设置背景高斯模糊voidsetCanvasRoundCorner(Integer roundCorner) 设置画布圆角(针对整图)setPositionBaseCentre(boolean positionBaseCentre) 计算x,y坐标的时候是否从中心做为原始坐标开始计算setQuality(double quality) 设置图片输出质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩setQuality(float quality) 设置图片输出质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩setTargetImageType(String imgType) 设置目标图片文件格式,用于写出描边,此方法为向内描边,会覆盖图片相应的位置描边,此方法为向内描边,会覆盖图片相应的位置boolean写出图像为目标文件扩展名对应的格式booleanwrite(OutputStream out) 写出图像为结果设置格式 结果类型设定见setTargetImageType(String)booleanwrite(ImageOutputStream targetImageStream) 写出图像为结果设置格式 结果类型设定见setTargetImageType(String)
-
Constructor Details
-
Images
-
Images
-
Images
- Parameters:
canvasWidth- 画布宽canvasHeight- 画布高fileType- 输出图片格式
-
Images
-
Images
构造- Parameters:
srcImage- 来源图片fileType- 目标图片类型,null则读取来源图片类型
-
Images
构造:图片合成专用- Parameters:
srcImage- 背景图片对象(画布以背景图宽高为基准)imageUrl- 背景图片地址(画布以背景图宽高为基准)fileType- 输出图片格式
-
Images
- Parameters:
bgImageUrl- 背景图片地址width- 背景图宽度height- 背景图高度zoom- 缩放模式fileType- 输出图片格式
-
Images
- Parameters:
bgImage- 背景图片对象width- 背景图宽度height- 背景图高度zoomMode- 缩放模式fileType- 输出图片格式
-
-
Method Details
-
from
-
from
-
from
-
from
-
from
从ImageInputStream取图片并开始处理- Parameters:
imageStream- 图片流- Returns:
Images
-
from
-
from
-
from
图片合成专用-读取图片- Parameters:
srcImage- 背景图片对象(画布以背景图宽高为基准)imageUrl- 背景图片地址(画布以背景图宽高为基准)fileType- 输出图片格式- Returns:
Images
-
makeBlur
高斯模糊(毛玻璃效果)- Parameters:
srcImage- 图片流radius- 半径- Returns:
- 图片流
-
makeRoundCorner
public static BufferedImage makeRoundCorner(BufferedImage srcImage, int width, int height, int radius) 圆角- Parameters:
srcImage- 图片流width- 宽度height- 高度radius- 半径- Returns:
- 图片流
-
setTargetImageType
-
setPositionBaseCentre
计算x,y坐标的时候是否从中心做为原始坐标开始计算- Parameters:
positionBaseCentre- 是否从中心做为原始坐标开始计算- Returns:
- the image
-
setQuality
设置图片输出质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩- Parameters:
quality- 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩- Returns:
- the image
-
setQuality
设置图片输出质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩- Parameters:
quality- 质量,数字为0~1(不包括0和1)表示质量压缩比,除此数字外设置表示不压缩- Returns:
- image
-
scale
缩放图像(按比例缩放)- Parameters:
scale- 缩放比例 比例大于1时为放大,小于1大于0为缩小- Returns:
- this
-
scale
缩放图像(按长宽缩放) 注意:目标长宽与原图不成比例会变形- Parameters:
width- 目标宽度height- 目标高度- Returns:
- this
-
scale
缩放图像(按长宽缩放) 注意:目标长宽与原图不成比例会变形- Parameters:
width- 目标宽度height- 目标高度scaleType- 缩放类型,可选Image.SCALE_SMOOTH平滑模式或Image.SCALE_DEFAULT默认模式- Returns:
- this
-
scale
-
cut
-
cut
图像切割为圆形(按指定起点坐标和半径切割),填充满整个图片(直径取长宽最小值)- Parameters:
x- 原图的x坐标起始位置y- 原图的y坐标起始位置- Returns:
- this
-
cut
图像切割为圆形(按指定起点坐标和半径切割)- Parameters:
x- 原图的x坐标起始位置y- 原图的y坐标起始位置radius- 半径,小于0表示填充满整个图片(直径取长宽最小值)- Returns:
- this
-
round
-
gray
-
binary
-
pressText
给图片添加文字水印 此方法只在给定位置写出一个水印字符串- Parameters:
pressText- 水印文字color- 水印的字体颜色font-Font字体相关信息x- 修正值。 默认在中间,偏移量相对于中间偏移y- 修正值。 默认在中间,偏移量相对于中间偏移alpha- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字- Returns:
- 处理后的图像
-
pressText
-
pressTextFull
public Images pressTextFull(String pressText, Color color, Font font, int lineHeight, int degree, float alpha) 给图片添加全屏文字水印- Parameters:
pressText- 水印文字,文件间的间隔使用尾部添加空格方式实现color- 水印的字体颜色font-Font字体相关信息lineHeight- 行高degree- 旋转角度,(单位:弧度),以圆点(0,0)为圆心,正代表顺时针,负代表逆时针alpha- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字- Returns:
- 处理后的图像
-
pressImage
给图片添加图片水印- Parameters:
pressImage- 水印图片,可以使用ImageIO.read(File)方法读取文件x- 修正值 默认在中间,偏移量相对于中间偏移y- 修正值 默认在中间,偏移量相对于中间偏移alpha- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字- Returns:
- this
-
pressImage
给图片添加图片水印- Parameters:
pressImage- 水印图片,可以使用ImageIO.read(File)方法读取文件rectangle- 矩形对象,表示矩形区域的x,y,width,height,x,y从背景图片中心计算alpha- 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字- Returns:
- this
-
rotate
旋转图片为指定角度 来自:http://blog.51cto.com/cping1982/130066- Parameters:
degree- 旋转角度- Returns:
- 旋转后的图片
-
flip
-
getImg
-
write
写出图像为结果设置格式 结果类型设定见setTargetImageType(String)- Parameters:
out- 写出到的目标流- Returns:
- 是否成功写出, 如果返回false表示未找到合适的Writer
- Throws:
InternalException- IO异常
-
write
写出图像为结果设置格式 结果类型设定见setTargetImageType(String)- Parameters:
targetImageStream- 写出到的目标流- Returns:
- 是否成功写出, 如果返回false表示未找到合适的Writer
- Throws:
InternalException- IO异常
-
write
写出图像为目标文件扩展名对应的格式- Parameters:
targetFile- 目标文件- Returns:
- 是否成功写出, 如果返回false表示未找到合适的Writer
- Throws:
InternalException- IO异常
-
stroke
-
stroke
描边,此方法为向内描边,会覆盖图片相应的位置- Parameters:
color- 描边颜色,默认黑色stroke- 描边属性,包括粗细、线条类型等,见BasicStroke- Returns:
- this
-
getInputStream
获取合成后的图片流- Returns:
InputStream- Throws:
Exception- 异常
-
merge
合成图片,返回图片对象- Returns:
BufferedImage- Throws:
Exception- 异常
-
addElement
-
out
保存合成后的图片- Parameters:
filePath- 完整保存路径,如 “d://123.jpg”- Throws:
IOExceptionException
-
addImageElement
添加图片元素- Parameters:
image- 图片对象x- x坐标y- y坐标- Returns:
ImageElement
-
addImageElement
添加图片元素- Parameters:
imgUrl- 图片地址x- x坐标y- y坐标- Returns:
ImageElement
-
addImageElement
public ImageElement addImageElement(String imgUrl, int x, int y, int width, int height, Scale.Zoom zoom) 添加图片元素- Parameters:
imgUrl- 图片地址x- x坐标y- y坐标width- 宽度height- 高度zoom- 缩放模式- Returns:
ImageElement
-
addTextElement
添加文本元素- Parameters:
text- 文本font- Font对象x- x坐标y- y坐标- Returns:
TextElement
-
addTextElement
添加文本元素- Parameters:
text- 文本fontSize- 字体大小x- x坐标y- y坐标- Returns:
TextElement
-
addTextElement
添加文本元素- Parameters:
text- 文本fontName- 字体名称fontSize- 字体大小x- x坐标y- y坐标- Returns:
TextElement
-
addRectangleElement
添加矩形元素- Parameters:
x- x坐标y- y坐标width- 宽度height- 高度- Returns:
- the object
-
addImageElement
public ImageElement addImageElement(BufferedImage image, int x, int y, int width, int height, Scale.Zoom zoom) 添加图片元素- Parameters:
image- 图片对象x- x坐标y- y坐标width- 宽度height- 高度zoom- 缩放模式- Returns:
ImageElement
-
setBackgroundBlur
public void setBackgroundBlur(int blur) 设置背景高斯模糊- Parameters:
blur- 模糊值
-
setCanvasRoundCorner
-
getCanvasWidth
public int getCanvasWidth()获取画布宽度- Returns:
- the int
-
getCanvasHeight
public int getCanvasHeight()获取画布高度- Returns:
- the int
-
getSrcImage
-