@Override protected BufferedImage crop(BufferedImage image, int iteration) { float ratio = HearthstoneAnalyser.getRatio(image); int x = (int) (8 * ratio); int y = (int) (53 * ratio); int width = (int) (236 * ratio); int height = (int) (30 * ratio); return image.getSubimage(x, y, width, height); }
/** * Saves a PNG image in the temp/extraction folder, cropped as specified. Ths image is saved on a * background thread so that detection isn't held up. * * <p>The code assumes that it has been given a full-size Hearthstone screenshot, and so the * position of the crop is adjusted to the relative position for the actual screen in the image. * In other words, if the screenshot is higher resolution or lower resolution than the reference * 1600x1200 size then the crop is moved accordingly. * * @param image The image to save. You should not make any further changes to this image on the * main thread after submitting it to this method, otherwise the save file will have * unpredictable contents. * @param filename The name of the file to save. Do not include the extension (.png is added * automatically) * @param x the X coordinate of the upper-left corner of the crop, relative to a 1600-pixel wide * screen * @param y the Y coordinate of the upper-left corner of the crop, relative to a 1200-pixel high * screen * @param w the width of the specified rectangular region, relative to a 1600-pixel wide screen * @param h the height of the specified rectangular region, relative to a 1200-pixel high screen */ public static void saveCroppedPngImage( final BufferedImage image, final String filename, int x, int y, int w, int h) { float ratio = HearthstoneAnalyser.getRatio(image); int xOffset = HearthstoneAnalyser.getXOffset(image, ratio); int relativeX = (int) (x * ratio + xOffset); int relativeY = (int) (y * ratio); int relativeWidth = (int) (w * ratio); int relativeHeight = (int) (h * ratio); debugLog.debug( "Cropping image to x={} y={} width={} height={}", relativeX, relativeY, relativeWidth, relativeHeight); BufferedImage croppedImage = image.getSubimage(relativeX, relativeY, relativeWidth, relativeHeight); savePngImage(croppedImage, filename); }