我在JSP中创建了图像裁剪的代码,但它仅适用于1个图像。对于其他图像,它会给出错误:
java.awt.image.RasterFormatException: (x + width) is outside of Raster
代码:
try {
File image = new File("C://Users/Gc/Documents/NetBeansProjects/cropDemo/build/web/images/logo.png");
BufferedImage image1 = ImageIO.read(image);
BufferedImage crop = image1.getSubimage(557, 47, 600, 200);
out.print(crop);
ImageIO.write(crop, "png", new File("C://Users/Gc/Documents/NetBeansProjects/cropDemo/build/web/images/11.png"));
String path = image.getName().trim();
String path1 = "C://Users/Gc/Documents/NetBeansProjects/cropDemo/build/web/images/11.png";
} catch(Exception e) {
out.print(e);
}
答案 0 :(得分:0)
当[x,y:x + width,y + height]指定的区域不包含在BufferedImage区域中时,getSubImage()抛出RasterFormatException。 在你的情况下,x +宽度在缓冲图像区域之外。因此你需要根据图像区域给出x +宽度和y +高度的动态值