public class ImageTools extends Object
| 限定符和类型 | 字段和说明 |
|---|---|
static String |
BIG_IMG
为每个上传图片生成一个大图的规则
|
static Integer |
BIG_IMG_HEIGHT |
static Integer |
BIG_IMG_WIDTH |
| 构造器和说明 |
|---|
ImageTools() |
| 限定符和类型 | 方法和说明 |
|---|---|
static void |
cutImage(File image,
String outputFile,
int x,
int y,
int width,
int height) |
static void |
cutImage(File image,
String outputFile,
Rectangle rect) |
static String |
cutImageComplex(String imgPath,
String baseRealPath,
String filePath,
int x,
int y,
int width,
int height)
已过时。
|
static boolean |
fillScaleImg(String srcImg,
String descImg,
int width,
int height,
boolean enlarge)
等比例缩放图片,不满足指定宽高时用白底填充图片
|
static Image |
getImageInfo(File fileImage) |
static void |
main(String[] args) |
static void |
mergeImages(String source1,
String source2,
String des,
String type,
int x,
int y,
int width,
int height) |
static Image[] |
resizeImage(BufferedImage img,
String imgName,
String baseRealPath,
boolean scale,
boolean enlarge,
List<Image> resizeImg)
已过时。
|
static int[] |
scaleSize(int originWidth,
int originHeight,
Integer width,
Integer height,
boolean scale,
boolean enlarge)
获取等比例的宽高
|
static CodeMsg |
validateImgs(String rules,
File... imgs) |
static CodeMsg |
validateImgs(String rules,
ImageInputStream[] imgs,
long[] fileSizes,
Integer maxSize,
boolean transaction)
注意:需要手动释放InputStream的资源
返回"suc"验证成功,除此之外都为验证失败 wl(900) ==> 宽度小于等于900px wg(900) ==> 宽度大于等于900px hl(900) ==> 高度小于等于900px hg(900) ==> 高度大于等于900px re(0.5) ==> 比例(ratio)等于0.5(宽/高=0.5),容错比例为0.1 rl(0.5) ==> 比例(ratio)小于等于0.5(宽/高<=0.5) rg(0.5) ==> 比例(ratio)大于等于0.5(宽/高>=0.5) sl(8) ==> 大小(size)小于等于8M sg(8) ==> 大小(size)大于等于8M type(jpg,png) ==> 文件格式 只能为jpg,png |
static CodeMsg |
validateImgs(String rules,
InputStream[] imgs,
long[] fileSizes,
Integer maxSize,
boolean transaction)
注意:需要手动释放InputStream的资源
|
public static final Integer BIG_IMG_WIDTH
public static final Integer BIG_IMG_HEIGHT
public static CodeMsg validateImgs(String rules, InputStream[] imgs, long[] fileSizes, Integer maxSize, boolean transaction)
maxSize - 文件的最大值,为null、负值、0时不验证此特性:单位MBtransaction - 是否一个文件验证失败后,所有的文件都失败public static CodeMsg validateImgs(String rules, ImageInputStream[] imgs, long[] fileSizes, Integer maxSize, boolean transaction)
rules - 图片的规则maxSize - 文件的最大值,为null、负值、0时不验证此特性:单位MBtransaction - 是否一个文件验证失败后,所有的文件都失败public static boolean fillScaleImg(String srcImg, String descImg, int width, int height, boolean enlarge)
srcImg - descImg - width - height - enlarge - 是否能够放大图片public static int[] scaleSize(int originWidth,
int originHeight,
Integer width,
Integer height,
boolean scale,
boolean enlarge)
originWidth - originHeight - width - 可以为空,为null就等比例缩放height - 可以为空,为null就等比例缩放scale - 是否等比缩放标记enlarge - 是否能够放大图片public static void cutImage(File image, String outputFile, Rectangle rect) throws IOException
IOExceptionpublic static void cutImage(File image, String outputFile, int x, int y, int width, int height) throws IOException
IOExceptionpublic static void mergeImages(String source1, String source2, String des, String type, int x, int y, int width, int height) throws Exception
Exception@Deprecated public static Image[] resizeImage(BufferedImage img, String imgName, String baseRealPath, boolean scale, boolean enlarge, List<Image> resizeImg) throws Exception
imgName - 如果resizeImg对象的imgName有值,则依据imgName否则图片名用该参数scale - 是够是等比例缩放,如果resizeImg中的宽、高有一个没值就强制等比例缩放enlarge - 是否能够放大图片resizeImg - 期望缩放的图片信息Exception@Deprecated public static String cutImageComplex(String imgPath, String baseRealPath, String filePath, int x, int y, int width, int height) throws Exception
imgPath - 大图的地址 upload/img/gift/1.pngbaseRealPath - filePath - upload/img/gift=300c0boundw - 裁剪图片宽度boundh - 裁剪图片高度cx - 裁剪图片的x点cy - 裁剪图片的y点cw - 裁剪的宽度ch - 裁剪高度Exceptionpublic static void main(String[] args)
Copyright © 2016. All rights reserved.