code: public static void captureScreenRect(final File file, final Rectangle rectangle) {
  		checkState(file.getName().endsWith("png"), "Screenshot file must have extension 'png': %s", file);
  		LOGGER.trace("Creating screenshot: {}", file);
  
  		try {
  			createParentDirs(file);
  			BufferedImage capture = new Robot().createScreenCapture(rectangle);
  			ImageIO.write(capture, "png", file);
  		} catch (AWTException ex) {
  			throw new JFunkException("Error capturing screen", ex);
  		} catch (IOException ex) {
  			throw new JFunkException("Error saving screenshot", ex);
  		}
  	}
docs: Captures the specified rectangle and saves it as png to the specified file. The file must
  have the extension {@code png}. Any necessary but non-existent parent directories of the
  specified file are created.
  
  @param file
  the file to save the screenshot to
  @param rectangle
  the rectangle to capture in screen coordinates