我正在Windows 8.1 64bit上开发一个JavaFX应用程序,带有4GB RAM,JDK版本为8u45 64bit.
我想使用Robot捕获部分屏幕,但问题是我无法获取我想要捕获的锚定窗格的屏幕坐标,我不想使用快照,因为输出质量很差.这是我的代码.
private void capturePane() {
try {
Bounds bounds = pane.getLayoutBounds();
Point2D coordinates = pane.localToScene(bounds.getMinX(), bounds.getMinY());
int X = (int) coordinates.getX();
int Y = (int) coordinates.getY();
int width = (int) pane.getWidth();
int height = (int) pane.getHeight();
Rectangle screenRect = new Rectangle(X, Y, width, height);
BufferedImage capture = new Robot().createScreenCapture(screenRect);
ImageIO.write(capture, "png", new File("image.png"));
} catch (IOException | AWTException ex) {
ex.printStackTrace();
}
}