/** * Removes a given region from the image. * @param image The image to crop. * @param regionToCrop The region to crop from the image. * @return A new image without the cropped region. */ public static BufferedImage cropImage(BufferedImage image, Region regionToCrop) { Region imageRegion = new Region(0,0, image.getWidth(), image.getHeight()); imageRegion.intersect(regionToCrop); if (imageRegion.isSizeEmpty()){ logger.log("WARNING - requested cropped area results in zero-size image! Cropped not performed. Returning original image."); return image; } if (!imageRegion.equals(regionToCrop)){ logger.log("WARNING - requested cropped area overflows image boundaries."); } BufferedImage croppedImage = Scalr.crop(image, imageRegion.getLeft(), imageRegion.getTop(), imageRegion.getWidth(), imageRegion.getHeight()); return normalizeImageType(croppedImage); }
/** * Removes a given region from the image. * @param logger The logger to use. * @param image The image to crop. * @param regionToCrop The region to crop from the image. * @return A new image without the cropped region. */ public static BufferedImage cropImage(Logger logger, BufferedImage image, Region regionToCrop) { Region imageRegion = new Region(0,0, image.getWidth(), image.getHeight()); imageRegion.intersect(regionToCrop); if (imageRegion.isSizeEmpty()){ logger.log("WARNING - requested cropped area results in zero-size image! Cropped not performed. Returning original image."); return image; } if (!imageRegion.equals(regionToCrop)){ logger.log("WARNING - requested cropped area overflows image boundaries."); } BufferedImage croppedImage = Scalr.crop(image, imageRegion.getLeft(), imageRegion.getTop(), imageRegion.getWidth(), imageRegion.getHeight()); return normalizeImageType(croppedImage); }