Skip to content

Commit b274488

Browse files
Extract getBufferedImage method
1 parent 06ed501 commit b274488

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

src/main/java/com/assertthat/selenium_shutterbug/utils/image/ImageProcessor.java

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,27 +63,21 @@ public static BufferedImage getElement(BufferedImage sourceImage, Coordinates co
6363

6464
public static BufferedImage blurArea(BufferedImage sourceImage, Coordinates coords) {
6565
BufferedImage blurredImage = blur(sourceImage.getSubimage(coords.getX(), coords.getY(), coords.getWidth(), coords.getHeight()));
66-
BufferedImage combined = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
67-
Graphics2D g = combined.createGraphics();
68-
g.drawImage(sourceImage, 0, 0, null);
69-
g.drawImage(blurredImage, coords.getX(), coords.getY(), null);
70-
g.dispose();
71-
return combined;
66+
return getBufferedImage(sourceImage, coords, blurredImage, sourceImage);
7267
}
7368

7469
public static BufferedImage monochromeArea(BufferedImage sourceImage, Coordinates coords) {
7570
BufferedImage monochromedImage = convertToGrayAndWhite(sourceImage.getSubimage(coords.getX(), coords.getY(), coords.getWidth(), coords.getHeight()));
76-
BufferedImage combined = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
77-
Graphics2D g = combined.createGraphics();
78-
g.drawImage(sourceImage, 0, 0, null);
79-
g.drawImage(monochromedImage, coords.getX(), coords.getY(), null);
80-
g.dispose();
81-
return combined;
71+
return getBufferedImage(sourceImage, coords, monochromedImage, sourceImage);
8272
}
8373

8474
public static BufferedImage blurExceptArea(BufferedImage sourceImage, Coordinates coords) {
8575
BufferedImage subImage = sourceImage.getSubimage(coords.getX(), coords.getY(), coords.getWidth(), coords.getHeight());
8676
BufferedImage blurredImage = blur(sourceImage);
77+
return getBufferedImage(sourceImage, coords, subImage, blurredImage);
78+
}
79+
80+
private static BufferedImage getBufferedImage(BufferedImage sourceImage, Coordinates coords, BufferedImage subImage, BufferedImage blurredImage) {
8781
BufferedImage combined = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB);
8882
Graphics2D g = combined.createGraphics();
8983
g.drawImage(blurredImage, 0, 0, null);

0 commit comments

Comments
 (0)