1

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 with JavaFX and need to provide functionality that allows to take a screenshot of web-page loaded into WebView component. The issue is that I need a screenshot of the full page, not only that piece that fits into current size of application window. Here is a simple code I use:

    WritableImage image = browser.snapshot(new SnapshotParameters(), null); 
    // browser is javafx.scene.web.WebView
    File file = new File("screenshot_fx.png");
    try {
        ImageIO.write(SwingFXUtils.fromFXImage(image, null), "png", file);
    } catch (IOException e) {
        e.printStackTrace();
    }

And it basically captures only what I see on the screen. If web-page requires scrolling -- I will not have not-visible part on the screenshot. Please suggest how to proceed.

Mikhail
  • 1,583
  • 5
  • 22
  • 34
  • See related sample: [capture web pages to image files using JavaFX WebView and ImageIO](https://gist.github.com/jewelsea/5632958) – jewelsea Oct 23 '14 at 21:23

1 Answers1

-1
        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.

Muten Roshi
  • 493
  • 2
  • 5
  • 17
  • He's trying to use the awt Robot, and so are you. Unfortunately it doesn't work with Javafx. At time of writing, the Robot will capture the Application title bar, and not much else. Did you try your example out? – wax_lyrical Jan 08 '16 at 14:34