public class Img extends Object
| 构造器和说明 |
|---|
Img(BufferedImage srcImage)
构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
Img |
binary()
彩色转为黑白二值化图片
|
Img |
cut(Rectangle rectangle)
图像切割(按指定起点坐标和宽高切割)
|
Img |
flip()
水平翻转图像
|
static Img |
from(File imageFile)
从文件读取图片并开始处理
|
static Img |
from(Image image)
从Image取图片并开始处理
|
static Img |
from(ImageInputStream imageStream)
从ImageInputStream取图片并开始处理
|
static Img |
from(InputStream in)
从流读取图片并开始处理
|
static Img |
from(URL imageUrl)
从URL取图片并开始处理
|
BufferedImage |
getImg()
获取处理过的图片
|
Img |
gray()
彩色转为黑白
|
Img |
pressImage(Image pressImg,
int x,
int y,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
Img |
pressImage(Image pressImg,
Rectangle rectangle,
float alpha)
给图片添加图片水印
此方法并不关闭流 |
Img |
pressText(String pressText,
Color color,
Font font,
int x,
int y,
float alpha)
给图片添加文字水印
此方法并不关闭流 |
Img |
rotate(int degree)
旋转图片为指定角度
来自:http://blog.51cto.com/cping1982/130066 |
Img |
scale(float scale)
缩放图像(按比例缩放)
|
Img |
scale(int width,
int height)
缩放图像(按长宽缩放)
注意:目标长宽与原图不成比例会变形 |
Img |
scale(int width,
int height,
Color fixedColor)
缩放图像(按高度和宽度缩放)
缩放后默认为jpeg格式 |
Img |
setDestImageType(String imgType)
设置目标图片文件格式,用于写出
|
void |
write(File targetFile)
写出图像为目标文件扩展名对应的格式
|
void |
write(ImageOutputStream destImageStream)
写出图像为PNG格式
|
void |
write(OutputStream out)
写出图像
|
public Img(BufferedImage srcImage)
srcImage - 来源图片public static Img from(InputStream in)
in - 图片流Imgpublic static Img from(ImageInputStream imageStream)
imageStream - 图片流Imgpublic Img setDestImageType(String imgType)
imgType - 图片格式ImageUtil.IMAGE_TYPE_JPG,
ImageUtil.IMAGE_TYPE_PNGpublic Img scale(float scale)
scale - 缩放比例。比例大于1时为放大,小于1大于0为缩小public Img scale(int width, int height)
width - 目标宽度height - 目标高度public Img scale(int width, int height, Color fixedColor)
width - 缩放后的宽度height - 缩放后的高度fixedColor - 比例不对时补充的颜色,不补充为nullpublic Img cut(Rectangle rectangle)
rectangle - 矩形对象,表示矩形区域的x,y,width,heightBufferedImagepublic Img gray()
public Img binary()
public Img 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 Img pressImage(Image pressImg, int x, int y, float alpha)
pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件x - 修正值。 默认在中间,偏移量相对于中间偏移y - 修正值。 默认在中间,偏移量相对于中间偏移alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public Img pressImage(Image pressImg, Rectangle rectangle, float alpha)
pressImg - 水印图片,可以使用ImageIO.read(File)方法读取文件rectangle - 矩形对象,表示矩形区域的x,y,width,height,x,y从背景图片中心计算alpha - 透明度:alpha 必须是范围 [0.0, 1.0] 之内(包含边界值)的一个浮点数字public Img rotate(int degree)
degree - 旋转角度public Img flip()
public BufferedImage getImg()
public void write(OutputStream out) throws IORuntimeException
out - 写出到的目标流IORuntimeException - IO异常public void write(ImageOutputStream destImageStream) throws IORuntimeException
destImageStream - 写出到的目标流IORuntimeException - IO异常public void write(File targetFile) throws IORuntimeException
targetFile - 目标文件IORuntimeException - IO异常Copyright © 2018. All rights reserved.