title: JavaFX 2.0+ WebView /WebEngine render web page to an image
body: <p>I'm looking for a way to load up a page and save the rendering as an image just as you would do with CutyCapt (QT + webkit EXE to do just that). </p>
  
  <p>At the moment and without JavaFX, I do it by calling an external process from java and rendering to file than loading that file into an ImageBuffer... Neither very optimized nor practical and even less cross platform...</p>
  
  <p>Using JavaFX2+ I tried playing with the WebView &amp; WebEngine:</p>
  
  <pre class="lang-java prettyprint-override"><code>public class WebComponentTrial extends Application {
      private Scene scene;
  
      @Override
      public void start(final Stage primaryStage) throws Exception {
          primaryStage.setTitle("Web View");
          final Browser browser = new Browser();
          scene = new Scene(browser, 1180, 800, Color.web("#666970"));
          primaryStage.setScene(scene);
          scene.getStylesheets().add("webviewsample/BrowserToolbar.css");
          primaryStage.show();
      }
  
      public static void main(final String[] args) {
          launch(args);
      }
  }
  class Browser extends Region {
      static { // use system proxy settings when standalone application
      // System.setProperty("java.net.useSystemProxies", "true");
      }
  
      final WebView browser = new WebView();
      final WebEngine webEngine = browser.getEngine();
  
      public Browser() {
          getStyleClass().add("browser");
          webEngine.load("http://www.google.com/");
          getChildren().add(browser);
      }
  
      @Override
      protected void layoutChildren() {
          final double w = getWidth();
          final double h = getHeight();
          layoutInArea(browser, 0, 0, w, h, 0, HPos.CENTER, VPos.CENTER);
      }
  
      @Override
      protected double computePrefWidth(final double height) {
          return 800;
      }
  
      @Override
      protected double computePrefHeight(final double width) {
          return 600;
      }
  }
  </code></pre>
  
  <p>There is a deprecated method : <code>renderToImage</code> in <code>Scene</code> (see links below) that would do something that comes close and with which I'd might be able to work but it is deprecated...
  It being deprecated in JavaFX seems to mean that there is no javadoc advertising the replacement method and because I don't have access to the code, I cannot see how it was done...</p>
  
  <p>Here are a couple of sites where I found some information but nothing to render a webpage to an image:</p>
  
  <pre><code>http://tornorbye.blogspot.com/2010/02/how-to-render-javafx-node-into-image.html
  </code></pre>
  
  <p><code>canvasImage</code> and <code>saveImage(canvasImage, fc.getSelectedFile())</code> from this one : </p>
  
  <pre><code>http://javafx.com/samples/EffectsPlayground/src/Main.fx.html
  </code></pre>
  
  <p>Others: </p>
  
  <pre><code>http://download.oracle.com/javafx/2.0/webview/jfxpub-webview.htm
  http://download.oracle.com/javafx/2.0/get_started/jfxpub-get_started.htm
  http://fxexperience.com/2011/05/maps-in-javafx-2-0/
  </code></pre>