/** * 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); }
private Region getRegionInScreenshot(Region region, BufferedImage image, double pixelRatio) { if (region.isSizeEmpty()) { return region; } logger.verbose("Creating screenshot object..."); // We need the screenshot to be able to convert the region to screenshot coordinates. EyesScreenshot screenshot = screenshotFactory.makeScreenshot(image); logger.verbose("Getting region in screenshot..."); // Region regionInScreenshot = screenshot.convertRegionLocation(regionProvider.getRegion(), regionProvider.getCoordinatesType(), CoordinatesType.SCREENSHOT_AS_IS); Region regionInScreenshot = screenshot.getIntersectedRegion(region, CoordinatesType.SCREENSHOT_AS_IS); logger.verbose("Region in screenshot: " + regionInScreenshot); regionInScreenshot = regionInScreenshot.scale(pixelRatio); logger.verbose("Scaled region: " + regionInScreenshot); regionInScreenshot = regionPositionCompensation.compensateRegionPosition(regionInScreenshot, pixelRatio); // Handling a specific case where the region is actually larger than // the screenshot (e.g., when body width/height are set to 100%, and // an internal div is set to value which is larger than the viewport). regionInScreenshot.intersect(new Region(0, 0, image.getWidth(), image.getHeight())); logger.verbose("Region after intersect: " + regionInScreenshot); return regionInScreenshot; } }
originalCoordinatesType, CoordinatesType.CONTEXT_RELATIVE); intersectedRegion.intersect(bounds);
region.getCoordinatesType(), CoordinatesType.CONTEXT_RELATIVE); intersectedRegion.intersect(bounds);
this.frameWindow.intersect(new Region(0, 0, image.getWidth(), image.getHeight())); if (this.frameWindow.getWidth() <= 0 || this.frameWindow.getHeight() <= 0) { throw new EyesException("Got empty frame window for screenshot!");
parentSize.getWidth(), parentSize.getHeight()); region.intersect(parentRegion); try { parent = parent.findElement(By.xpath(".."));
regionToCheck.intersect(effectiveViewport);
effectiveViewport.intersect(reg);