/**
* 图片裁剪
* @param srcImageFile 图片裁剪地址
* @param result 图片输出文件夹
* @param destWidth 图片裁剪宽度
* @param destHeight 图片裁剪高度
*/
public final static void cutImage(String srcImageFile, String result,
int destWidth, int destHeight) {
try {
Iterator iterator = ImageIO.getImageReadersByFormatName("JPEG");/*PNG,BMP*/
ImageReader reader = (ImageReader)iterator.next();/*获取图片尺寸*/
InputStream inputStream = new FileInputStream(srcImageFile);
ImageInputStream iis = ImageIO.createImageInputStream(inputStream);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
Rectangle rectangle = new Rectangle(0,0, destWidth, destHeight);/*指定截取范围*/
param.setSourceRegion(rectangle);
BufferedImage bi = reader.read(0,param);
ImageIO.write(bi, "JPEG", new File(result));
} catch (Exception e) {
LOG.error("图片裁剪出现异常:"+e);
}
}