Screenshot of the full web page loaded into JavaFX WebView component, not only visible part

后端 未结 1 1982
北荒
北荒 2021-01-16 09:02

I\'m writing my first lines of code after 2 years of managerial work. No time to read a lot of docs, need to create a proof-of-concept just in minutes. So I have to work wi

相关标签:
1条回答
  • 2021-01-16 09:54
            try {
                Robot pixelGrabber = new Robot();
                BufferedImage bi = pixelGrabber
                        .createScreenCapture(new Rectangle(x, y, width, height));
    
    
                Image screen = SwingFXUtils.toFXImage(bi,
                        new WritableImage(bi.getWidth(), bi.getHeight()));
    
            } catch (AWTException ex) {
                ex.printStackTrace();
            }
    

    This creates a screenshot starting on pixel x*y with your needed height and width independent of the current size of your application window. If your are using JavaFX, just use SwingFXUtils to transform the awt-image to a JavaFX-image.

    0 讨论(0)
提交回复
热议问题