public class ImageUtil extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
protected static org.apache.log4j.Logger |
LOGGER |
| 构造器和说明 |
|---|
ImageUtil() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
batchImageWidthHeight(String directoryPath,
int sSize,
int tSize)
批处理图片
|
static void |
ChangeImage(String root,
double scale)
缩放图像透明背景,捕捉到IOException异常后会抛出。
|
static void |
convert(String source,
String result)
图像类型转换 GIF->JPG GIF->PNG PNG->JPG PNG->GIF(X)
|
static void |
createImage(String path,
BufferedImage bi)
创建图片,根据BufferedImage流
|
static void |
createImage(String path,
byte[] bt)
创建图片,根据字节数组
|
static void |
cut(int x,
int y,
int width,
int height,
String sourceImagePath,
String savePath)
图片剪切
|
static void |
cut(String sourceImagePath,
String descDir,
int width,
int height)
图像切割
|
static void |
decodeImage(String sourceImagePath)
图片解密
|
static void |
encodeImage(String sourceImagePath)
图片加密
|
static void |
formatImage(String path,
String fix)
图片格式转换
|
static String |
getImageType(byte[] imageBytes)
根据字节流获取图片类型,jpeg,jpg,png
|
static int[] |
getImageWidthHeight(String sourceImagePath)
获取新图片宽度和高度
|
static void |
gray(String sourceImagePath,
String savePath)
彩色转为黑白
|
static void |
main(String[] args)
测试用主方法
|
static BufferedImage |
resize(String sourceImagePath,
int width,
int height)
重新设置图片的宽度高度
|
static boolean |
resizeImage(File sourceImagePath,
String savePath,
int width,
int height,
String sufix)
获取新图片宽度和高度 根据sourceWidth与targetWidth的比例,重新生成图片大小
|
static byte[] |
resizeImageForBytes(String sourceImagePath,
int targetW,
int targetH,
String type)
重置图片大小,输出字节流
|
static boolean |
resizeImageForEncode(File sourceImageFile,
String savePath,
Integer width,
Integer height,
String sufix)
获取新图片宽度和高度 根据sourceWidth与targetWidth的比例,重新生成图片大小
|
static void |
rotate(String sourceImagePath,
int direction)
图片旋转
|
static void |
saveImageAsJpg(String sourceImagePath,
String savePath,
int width,
int hight)
保存jpg图片
|
static void |
scale(String sourceImagePath,
String savePath,
double scale,
boolean flag)
缩放图像
|
static void |
scaleHyaline(String sourceImagePath,
String savePath,
double scale,
boolean flag)
缩放图像透明背景
|
static void |
zoom(String sourceImagePath,
String savePath,
int targetWidth,
int targetHeight,
boolean more,
String exp)
缩放图片
|
public static void batchImageWidthHeight(String directoryPath, int sSize, int tSize)
directoryPath - 批处理文件目录sSize - 源尺寸tSize - 处理后尺寸public static void ChangeImage(String root, double scale) throws IOException
root - 文件路径scale - 规模IOException - IO流异常public static void convert(String source, String result)
source - 源图片路径result - 输出图片路径public static void createImage(String path, BufferedImage bi)
path - 图片路径 bi - 图片对象流public static void createImage(String path, byte[] bt)
path - 图片路径 bt - 图片字节数public static void cut(String sourceImagePath, String descDir, int width, int height)
sourceImagePath - 源图像地址descDir - 输出图像地址width - 目标切片宽度height - 目标切片高度public static void decodeImage(String sourceImagePath)
sourceImagePath - 图片路径public static void encodeImage(String sourceImagePath)
sourceImagePath - 图片路径public static String getImageType(byte[] imageBytes)
imageBytes - 图像字节流public static int[] getImageWidthHeight(String sourceImagePath)
sourceImagePath - 源图片public static void gray(String sourceImagePath, String savePath)
sourceImagePath - 源图片路径savePath - 输出图片路径public static void main(String[] args) throws IOException
args - 主方法形参IOException - io异常public static BufferedImage resize(String sourceImagePath, int width, int height)
sourceImagePath - 图像位置width - 新的宽度height - 新的高度public static boolean resizeImage(File sourceImagePath, String savePath, int width, int height, String sufix)
sourceImagePath - 源文件savePath - 输出路径width - 源图片宽度height - 新图片宽度sufix - 图片后缀public static byte[] resizeImageForBytes(String sourceImagePath, int targetW, int targetH, String type)
sourceImagePath - 源图片路径targetW - 新图片宽度targetH - 新图片高度type - 图片类型jpg,png,bmp,gifpublic static boolean resizeImageForEncode(File sourceImageFile, String savePath, Integer width, Integer height, String sufix)
sourceImageFile - 源文件savePath - 输出路径width - 源图片宽度height - 新图片宽度sufix - 图片后缀public static void rotate(String sourceImagePath, int direction)
sourceImagePath - 图片文件路径direction - 旋转方向 0:顺时针90度 1逆时针90度public static void saveImageAsJpg(String sourceImagePath, String savePath, int width, int hight)
sourceImagePath - 原始图片地址savePath - 保存后的图片地址width - 新的图片宽度 0:不改变图片宽度hight - 新的图片高度 0:不改变图片高度public static void scale(String sourceImagePath, String savePath, double scale, boolean flag)
sourceImagePath - 源图像文件地址savePath - 缩放后的图像地址scale - 缩放比例flag - 缩放选择:true 放大; false 缩小;public static void scaleHyaline(String sourceImagePath, String savePath, double scale, boolean flag)
sourceImagePath - 源图像文件地址savePath - 缩放后的图像地址scale - 缩放比例flag - 缩放选择:true 放大; false 缩小;public static void cut(int x,
int y,
int width,
int height,
String sourceImagePath,
String savePath)
x - 剪切的起点x轴y - 剪切的起点y轴width - 剪切后的宽度height - 剪切后的高度sourceImagePath - 原始图片路径savePath - 剪切后保存的路径public static void formatImage(String path, String fix)
path - 图片路径 fix - 要转换成的文件格式,文件名后缀Copyright © 2016. All rights reserved.