Search in sources :

Example 36 with WritableImage

use of javafx.scene.image.WritableImage 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)

Example 37 with WritableImage

use of javafx.scene.image.WritableImage in project Gargoyle by callakrsos.

the class FxUtil method printJob.

/********************************
	 * 작성일 : 2016. 6. 29. 작성자 : KYJ
	 *
	 * print 처리.
	 *
	 * @param window
	 * @param target
	 ********************************/
public static void printJob(Window window, Node target) {
    Printer printer = Printer.getDefaultPrinter();
    // PrinterAttributes printerAttributes = printer.getPrinterAttributes();
    //
    Paper a4 = Paper.A4;
    // Paper a4 = PrintHelper.createPaper("Rotate A4", Paper.A4.getHeight(),
    // Paper.A4.getWidth(), Units.MM);
    PageLayout pageLayout = printer.createPageLayout(a4, PageOrientation.REVERSE_PORTRAIT, MarginType.DEFAULT);
    PrinterJob printerJob = PrinterJob.createPrinterJob();
    // JobSettings jobSettings = printerJob.getJobSettings();
    // jobSettings.setPrintSides(PrintSides.TUMBLE);
    ImageView imageView = new ImageView();
    // 화면 사이즈에 맞게 크기 조절.
    Callback<SnapshotResult, Void> callback = param -> {
        final WritableImage image = param.getImage();
        imageView.setImage(image);
        final double scaleX = pageLayout.getPrintableWidth() / imageView.getBoundsInParent().getWidth();
        final double scaleY = pageLayout.getPrintableHeight() / imageView.getBoundsInParent().getHeight();
        imageView.getTransforms().add(new Scale(scaleX, scaleY));
        return null;
    };
    target.snapshot(callback, null, null);
    if (printerJob.showPrintDialog(window) && printerJob.printPage(pageLayout, imageView))
        printerJob.endJob();
}
Also used : StageStyle(javafx.stage.StageStyle) PageOrientation(javafx.print.PageOrientation) Printer(javafx.print.Printer) SnapshotParameters(javafx.scene.SnapshotParameters) Transition(javafx.animation.Transition) AnimationType(jidefx.animation.AnimationType) PageLayout(javafx.print.PageLayout) TabPane(javafx.scene.control.TabPane) FontPosture(javafx.scene.text.FontPosture) Map(java.util.Map) Point2D(javafx.geometry.Point2D) PopOver(org.controlsfx.control.PopOver) Rectangle2D(javafx.geometry.Rectangle2D) Pair(javafx.util.Pair) Set(java.util.Set) SnapshotResult(javafx.scene.SnapshotResult) KeyEvent(javafx.scene.input.KeyEvent) Screen(javafx.stage.Screen) ScmCommitComposite(com.kyj.fx.voeditor.visual.component.scm.ScmCommitComposite) Platform(javafx.application.Platform) Stream(java.util.stream.Stream) Region(javafx.scene.layout.Region) FxContextManager(com.kyj.fx.voeditor.visual.framework.contextmenu.FxContextManager) ObservableList(javafx.collections.ObservableList) BorderPane(javafx.scene.layout.BorderPane) MouseButton(javafx.scene.input.MouseButton) TreeItem(javafx.scene.control.TreeItem) DockNode(com.kyj.fx.voeditor.visual.component.dock.pane.DockNode) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) FXMLLoader(javafx.fxml.FXMLLoader) GargoyleButtonBuilder(com.kyj.fx.voeditor.visual.framework.builder.GargoyleButtonBuilder) Color(javafx.scene.paint.Color) Properties(java.util.Properties) TitledPane(javafx.scene.control.TitledPane) Node(javafx.scene.Node) PopupFeatures(javafx.scene.web.PopupFeatures) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) FileChooser(javafx.stage.FileChooser) Tab(javafx.scene.control.Tab) ImageView(javafx.scene.image.ImageView) ObservableValue(javafx.beans.value.ObservableValue) SkinManager(com.kyj.fx.voeditor.visual.momory.SkinManager) Image(javafx.scene.image.Image) Button(javafx.scene.control.Button) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) JavaTextArea(com.kyj.fx.voeditor.visual.component.text.JavaTextArea) ToExcelFileFunction(com.kyj.fx.voeditor.visual.functions.ToExcelFileFunction) WebEvent(javafx.scene.web.WebEvent) JavaSVNManager(com.kyj.scm.manager.svn.java.JavaSVNManager) SvnChagnedCodeComposite(com.kyj.fx.voeditor.visual.component.scm.SvnChagnedCodeComposite) Parent(javafx.scene.Parent) FileSystemView(javax.swing.filechooser.FileSystemView) Task(javafx.concurrent.Task) InstanceTypes(com.kyj.fx.voeditor.visual.framework.InstanceTypes) ImageIO(javax.imageio.ImageIO) WindowEvent(javafx.stage.WindowEvent) TableView(javafx.scene.control.TableView) Method(java.lang.reflect.Method) AutoCompletionTextFieldBinding(impl.org.controlsfx.autocompletion.AutoCompletionTextFieldBinding) FxSVNHistoryDataSupplier(com.kyj.fx.voeditor.visual.component.scm.FxSVNHistoryDataSupplier) TextField(javafx.scene.control.TextField) GargoyleLoadBar(com.kyj.fx.voeditor.visual.component.bar.GargoyleLoadBar) Paper(javafx.print.Paper) BufferedImage(java.awt.image.BufferedImage) Predicate(java.util.function.Predicate) FXMLController(com.kyj.fx.voeditor.visual.framework.annotation.FXMLController) Font(javafx.scene.text.Font) Icon(javax.swing.Icon) Collectors(java.util.stream.Collectors) FxPostInitialize(com.kyj.fx.voeditor.visual.framework.annotation.FxPostInitialize) MarginType(javafx.print.Printer.MarginType) List(java.util.List) Modifier(java.lang.reflect.Modifier) Scale(javafx.scene.transform.Scale) Optional(java.util.Optional) FontWeight(javafx.scene.text.FontWeight) AnimationUtils(jidefx.animation.AnimationUtils) Scene(javafx.scene.Scene) GargoyleBuilderFactory(com.kyj.fx.voeditor.visual.framework.builder.GargoyleBuilderFactory) WebEngine(javafx.scene.web.WebEngine) TextArea(javafx.scene.control.TextArea) MouseEvent(javafx.scene.input.MouseEvent) WebViewConsole(com.kyj.fx.voeditor.visual.component.console.WebViewConsole) Function(java.util.function.Function) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) Charset(java.nio.charset.Charset) State(javafx.concurrent.Worker.State) JavaTextView(com.kyj.fx.voeditor.visual.component.popup.JavaTextView) Callback(javafx.util.Callback) Tooltip(javafx.scene.control.Tooltip) GargoyleException(com.kyj.fx.voeditor.visual.exceptions.GargoyleException) FxMemory(com.kyj.fx.voeditor.visual.momory.FxMemory) PrinterJob(javafx.print.PrinterJob) OutputStream(java.io.OutputStream) KeyCode(javafx.scene.input.KeyCode) WebView(javafx.scene.web.WebView) Modality(javafx.stage.Modality) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) CloseableParent(com.kyj.fx.voeditor.visual.main.layout.CloseableParent) TablePosition(javafx.scene.control.TablePosition) WritableImage(javafx.scene.image.WritableImage) FileInputStream(java.io.FileInputStream) Consumer(java.util.function.Consumer) GargoyleSynchLoadBar(com.kyj.fx.voeditor.visual.component.bar.GargoyleSynchLoadBar) Stage(javafx.stage.Stage) Closeable(java.io.Closeable) SwingFXUtils(javafx.embed.swing.SwingFXUtils) Window(javafx.stage.Window) ChangeListener(javafx.beans.value.ChangeListener) InputStream(java.io.InputStream) SharedMemory(com.kyj.fx.voeditor.visual.momory.SharedMemory) WritableImage(javafx.scene.image.WritableImage) SnapshotResult(javafx.scene.SnapshotResult) PageLayout(javafx.print.PageLayout) Paper(javafx.print.Paper) Scale(javafx.scene.transform.Scale) ImageView(javafx.scene.image.ImageView) Printer(javafx.print.Printer) PrinterJob(javafx.print.PrinterJob)

Example 38 with WritableImage

use of javafx.scene.image.WritableImage in project Gargoyle by callakrsos.

the class FxUtil method snapShot.

public static void snapShot(Scene target, OutputStream out, int requestWidth, int requestHeight, Consumer<Exception> errorCallback) {
    if (target == null)
        throw new NullPointerException("target Node is empty.");
    if (out == null)
        throw new NullPointerException("target Stream is empty.");
    SnapshotParameters params = new SnapshotParameters();
    params.setDepthBuffer(true);
    // params.setFill(Color.TRANSPARENT);
    WritableImage wi = null;
    if (requestWidth >= 0 || requestHeight >= 0) {
        wi = new WritableImage(requestWidth, requestHeight);
    }
    WritableImage snapshot = target.snapshot(wi);
    try {
        boolean isSuccess = snapShot(out, snapshot);
        LOGGER.debug("Write Image result {}", isSuccess);
    } catch (IOException e) {
        errorCallback.accept(e);
    }
}
Also used : WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) IOException(java.io.IOException)

Example 39 with WritableImage

use of javafx.scene.image.WritableImage in project latexdraw by arnobl.

the class Export method createRenderedImage.

/**
 * @return A writable image that contains given views (not null).
 */
private BufferedImage createRenderedImage() {
    final Group views = canvas.getViews();
    final Bounds bounds = views.getBoundsInParent();
    final double scale = 3d;
    final WritableImage img = new WritableImage((int) (bounds.getWidth() * scale), (int) (bounds.getHeight() * scale));
    final SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setFill(Color.WHITE);
    snapshotParameters.setTransform(new Scale(scale, scale));
    views.snapshot(snapshotParameters, img);
    while (img.isBackgroundLoading()) {
        LSystem.INSTANCE.sleep(100L);
    }
    return SwingFXUtils.fromFXImage(img, null);
}
Also used : Group(javafx.scene.Group) WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) Bounds(javafx.geometry.Bounds) Scale(javafx.scene.transform.Scale)

Example 40 with WritableImage

use of javafx.scene.image.WritableImage in project latexdraw by arnobl.

the class ViewSingleShape method getHatchingsFillingPaint.

private Paint getHatchingsFillingPaint(final FillingStyle style) {
    final Bounds bounds = border.getBoundsInParent();
    if (bounds.getWidth() > 0d && bounds.getHeight() > 0d) {
        final Group hatchings = new Group();
        final double hAngle = model.getHatchingsAngle();
        hatchings.getChildren().add(new Rectangle(bounds.getWidth(), bounds.getHeight(), style.isFilled() ? model.getFillingCol().toJFX() : null));
        if (style == FillingStyle.VLINES || style == FillingStyle.VLINES_PLAIN) {
            computeHatchings(hatchings, hAngle, bounds.getWidth(), bounds.getHeight());
        } else {
            if (style == FillingStyle.HLINES || style == FillingStyle.HLINES_PLAIN) {
                computeHatchings(hatchings, hAngle > 0d ? hAngle - Math.PI / 2d : hAngle + Math.PI / 2d, bounds.getWidth(), bounds.getHeight());
            } else {
                if (style == FillingStyle.CLINES || style == FillingStyle.CLINES_PLAIN) {
                    computeHatchings(hatchings, hAngle, bounds.getWidth(), bounds.getHeight());
                    computeHatchings(hatchings, hAngle > 0d ? hAngle - Math.PI / 2d : hAngle + Math.PI / 2d, bounds.getWidth(), bounds.getHeight());
                }
            }
        }
        final WritableImage image = new WritableImage((int) bounds.getWidth(), (int) bounds.getHeight());
        Platform.runLater(() -> hatchings.snapshot(new SnapshotParameters(), image));
        return new ImagePattern(image, 0, 0, 1, 1, true);
    }
    return null;
}
Also used : Group(javafx.scene.Group) WritableImage(javafx.scene.image.WritableImage) SnapshotParameters(javafx.scene.SnapshotParameters) Bounds(javafx.geometry.Bounds) Rectangle(javafx.scene.shape.Rectangle) ImagePattern(javafx.scene.paint.ImagePattern)

Aggregations

WritableImage (javafx.scene.image.WritableImage)70 SnapshotParameters (javafx.scene.SnapshotParameters)24 PixelWriter (javafx.scene.image.PixelWriter)21 PixelReader (javafx.scene.image.PixelReader)13 IOException (java.io.IOException)12 Color (javafx.scene.paint.Color)11 BufferedImage (java.awt.image.BufferedImage)9 File (java.io.File)8 Image (javafx.scene.image.Image)6 ImageView (javafx.scene.image.ImageView)6 Group (javafx.scene.Group)5 Random (java.util.Random)4 Canvas (javafx.scene.canvas.Canvas)4 GraphicsContext (javafx.scene.canvas.GraphicsContext)4 Texture (com.almasb.fxgl.texture.Texture)3 OutputStream (java.io.OutputStream)3 Point2D (javafx.geometry.Point2D)3 Scene (javafx.scene.Scene)3 Background (javafx.scene.layout.Background)3 Scale (javafx.scene.transform.Scale)3