Skip to content

Commit d2e88f3

Browse files
committed
Determine screen by position of program
1 parent 3342299 commit d2e88f3

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>dev.elektronisch</groupId>
88
<artifactId>screenshotTool</artifactId>
9-
<version>1.1</version>
9+
<version>1.2</version>
1010

1111
<properties>
1212
<maven.compiler.source>1.8</maven.compiler.source>

src/main/java/dev/elektronisch/screenshot/ScreenshotToolApplication.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
public final class ScreenshotToolApplication {
2121

22-
private static final double CURRENT_VERSION = 1.1;
22+
private static final double CURRENT_VERSION = 1.2;
2323

2424
private final DefaultListModel<String> urlListModel = new DefaultListModel<>();
2525
private final int[] emptyIntArray = new int[]{};
@@ -59,7 +59,7 @@ private void addWindowComponents() {
5959
frame.setVisible(false);
6060
try {
6161
Thread.sleep(200);
62-
final BufferedImage image = ScreenCaptureUtil.captureScreen();
62+
final BufferedImage image = ScreenCaptureUtil.captureScreen(frame.getX(), frame.getY());
6363
urlListModel.add(0, "Hochladen ...");
6464
frame.setVisible(true);
6565

src/main/java/dev/elektronisch/screenshot/util/ScreenCaptureUtil.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,25 @@
66
public final class ScreenCaptureUtil {
77

88
private static Robot robot;
9-
private static Rectangle screenRectangle;
9+
private static GraphicsEnvironment environment;
1010

1111
static {
1212
try {
1313
robot = new Robot();
14-
screenRectangle = new Rectangle(Toolkit.getDefaultToolkit().getScreenSize());
14+
environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
1515
} catch (final AWTException ignored) {
1616
}
1717
}
1818

1919
private ScreenCaptureUtil() {
2020
}
2121

22-
public static BufferedImage captureScreen() {
23-
return robot.createScreenCapture(screenRectangle);
22+
public static BufferedImage captureScreen(final int x, final int y) {
23+
for (final GraphicsDevice device : environment.getScreenDevices()) {
24+
final GraphicsConfiguration configuration = device.getConfigurations()[0];
25+
final Rectangle bounds = configuration.getBounds();
26+
if (x >= bounds.getMinX() && x <= bounds.getMaxX()) return robot.createScreenCapture(bounds);
27+
}
28+
return null;
2429
}
2530
}

0 commit comments

Comments
 (0)