public String cutLocalImage(String imagePath) {
File path = new File(new StringBuffer().append(Constant.NGNIX_DISK).append(File.separator).append(nfurlPath).toString());
String url = "";
FileInputStream fis = null;
ImageInputStream iis = null;
try {
/**读取图片*/
Iterator<ImageReader> it = ImageIO.getImageReadersByFormatName("png");
ImageReader reader = it.next();
/**获取图片流*/
fis = new FileInputStream(imagePath);
iis = ImageIO.createImageInputStream(fis);
reader.setInput(iis, true);
ImageReadParam param = reader.getDefaultReadParam();
Rectangle rect = new Rectangle(x, y, width, height);
param.setSourceRegion(rect);
BufferedImage bi = reader.read(0, param);
ImageIO.write(bi, "png", path);
} catch (Exception e) {
log.error(e.getMessage());
e.printStackTrace();
} finally {
try {
if (fis != null) {
fis.close();
}
if (iis != null) {
iis.close();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
图片切割
最新推荐文章于 2024-08-05 17:27:55 发布