title: How crop some region of image in Java?
body: <p>I'm trying do the following code:</p>
  
  <pre><code>private void crop(HttpServletRequest request, HttpServletResponse response){
      int x = 100;
      int y = 100;
      int w = 3264;
      int h = 2448;
  
      String path = "D:images\\upload_final\\030311175258.jpg";
  
      BufferedImage image = ImageIO.read(new File(path));
      BufferedImage out = image.getSubimage(x, y, w, h);
  
      ImageIO.write(out, "jpg", new File(path));
  
  }
  </code></pre>
  
  <p>But keeps giving me the same error:</p>
  
  <pre><code>java.awt.image.RasterFormatException: (x + width) is outside of Raster
  sun.awt.image.ByteInterleavedRaster.createWritableChild(ByteInterleavedRaster.java:1230)
      java.awt.image.BufferedImage.getSubimage(BufferedImage.java:1156)
  </code></pre>
  
  <p>Where is my mistake ?</p>