Search in sources :

Example 11 with SnapshotParameters

use of javafx.scene.SnapshotParameters in project jgnash by ccavanaugh.

the class ChartUtilities method takeSnapshot.

private static WritableImage takeSnapshot(final Pane pane) {
    Map<Chart, Boolean> animationMap = new HashMap<>();
    // Need to disable chart animations for printing
    pane.getChildren().stream().filter(node -> node instanceof Chart).forEach(node -> {
        animationMap.put((Chart) node, ((Chart) node).getAnimated());
        ((Chart) node).setAnimated(false);
    });
    final SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(SNAPSHOT_SCALE_FACTOR, SNAPSHOT_SCALE_FACTOR));
    final WritableImage image = pane.snapshot(snapshotParameters, null);
    // Restore animation
    for (Map.Entry<Chart, Boolean> entry : animationMap.entrySet()) {
        entry.getKey().setAnimated(entry.getValue());
    }
    return image;
}
Also used : StaticUIMethods(jgnash.uifx.StaticUIMethods) MainView(jgnash.uifx.views.main.MainView) ResourceUtils(jgnash.util.ResourceUtils) WritableImage(javafx.scene.image.WritableImage) IOException(java.io.IOException) HashMap(java.util.HashMap) SnapshotParameters(javafx.scene.SnapshotParameters) Chart(javafx.scene.chart.Chart) File(java.io.File) JavaFXUtils(jgnash.uifx.util.JavaFXUtils) FileChooser(javafx.stage.FileChooser) Clipboard(javafx.scene.input.Clipboard) Locale(java.util.Locale) ImageView(javafx.scene.image.ImageView) FileUtils(jgnash.util.FileUtils) Map(java.util.Map) ImageIO(javax.imageio.ImageIO) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Scale(javafx.scene.transform.Scale) ClipboardContent(javafx.scene.input.ClipboardContent) Pane(javafx.scene.layout.Pane) WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) HashMap(java.util.HashMap) Scale(javafx.scene.transform.Scale) HashMap(java.util.HashMap) Map(java.util.Map) Chart(javafx.scene.chart.Chart)

Aggregations

SnapshotParameters (javafx.scene.SnapshotParameters)11 WritableImage (javafx.scene.image.WritableImage)6 Image (javafx.scene.image.Image)5 ImagePattern (javafx.scene.paint.ImagePattern)4 IOException (java.io.IOException)3 Canvas (javafx.scene.canvas.Canvas)3 GraphicsContext (javafx.scene.canvas.GraphicsContext)3 LinearGradient (javafx.scene.paint.LinearGradient)3 Stop (javafx.scene.paint.Stop)3 ImageView (javafx.scene.image.ImageView)2 ClipboardContent (javafx.scene.input.ClipboardContent)2 File (java.io.File)1 YearMonth (java.time.YearMonth)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 SwingFXUtils (javafx.embed.swing.SwingFXUtils)1 Chart (javafx.scene.chart.Chart)1 PixelReader (javafx.scene.image.PixelReader)1 Clipboard (javafx.scene.input.Clipboard)1