package animation; import javafx.application.Application; import javafx.geometry.Pos; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.layout.*; import javafx.stage.Stage; public class SnapshotTest extends Application { public static void main(String[] args) throws Exception { launch(args); } @Override public void start(final Stage stage) throws Exception { // create an image and a snapshot copy of the image. final Image pizzaImage = new Image("http://icons.iconarchive.com/icons/aha-soft/desktop-buffet/128/Pizza-icon.png"); final ImageView originalImageView = new ImageView(pizzaImage); final ImageView originalImageViewAligned = new ImageView(pizzaImage); final ImageView snapshotImageView = new ImageView(); final ImageView snapshotImageViewAligned = new ImageView(); // layout the scene. final VBox layout = new VBox(5); layout.getChildren().addAll( VBoxBuilder.create().spacing(5).children( originalImageView, new Label("Original - unaligned"), snapshotImageView, new Label("Snapshot - unaligned") ).build(), VBoxBuilder.create().spacing(5).alignment(Pos.CENTER).children( originalImageViewAligned, new Label("Original - aligned"), snapshotImageViewAligned, new Label("Snapshot - aligned") ).build() ); layout.setStyle("-fx-padding: 10; -fx-background-color: cornsilk;"); stage.setScene(new Scene(layout, 300, 625)); stage.show(); // take snapshots of the aligned and unaligned nodes. snapshotImageView.setImage(originalImageView.snapshot(null, null)); snapshotImageViewAligned.setImage(originalImageViewAligned.snapshot(null, null)); } }