【问题标题】:Image Crop multiple images error图像裁剪多个图像错误
【发布时间】:2014-09-17 10:34:32
【问题描述】:

我在 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);
}

【问题讨论】:

    标签: java image jsp crop


    【解决方案1】:

    当 [ x,y : x+width, y+height] 指定的区域不包含在 BufferedImage 区域内时,getSubImage() 会抛出 RasterFormatException。 在您的情况下,x+width 在缓冲图像区域之外。因此您需要根据图像区域为 x+width 和 y+height 提供动态值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-09-03
      • 1970-01-01
      • 2017-05-22
      • 1970-01-01
      • 2012-06-04
      • 2011-10-20
      • 1970-01-01
      相关资源
      最近更新 更多