JavaFX scene Snapshot - Java JavaFX

Java examples for JavaFX:Scene

Description

JavaFX scene Snapshot

Demo Code


//package com.java2s;

import javafx.scene.Scene;
import javafx.scene.image.WritableImage;

import javafx.stage.Stage;

public class Main {

    private static WritableImage sceneSnapshot(Stage stage) {
        // Optimized by Albert: Use javaFX Scene API Complete Snapshot.
        if (null != stage && stage.sceneProperty() != null) {
            Scene currentScene = stage.sceneProperty().get();

            int width = (int) currentScene.widthProperty().get();
            int height = (int) currentScene.heightProperty().get();

            WritableImage image = currentScene.snapshot(new WritableImage(
                    width, height));/*ww w. j  av  a  2  s  .co m*/

            return image;
        }

        // ?
        return new WritableImage(800, 600);
    }
}

Related Tutorials