Search in sources :

Example 1 with JfxCanvas

use of com.xenoage.zong.renderer.javafx.canvas.JfxCanvas in project Zong by Xenoage.

the class JfxLayoutRenderer method paintToImage.

/**
 * Returns a {@link WritableImage} with the given page of the given {@link Layout}
 * which is rendered at the given zoom level.
 */
public static WritableImage paintToImage(Layout layout, int pageIndex, float zoom) {
    Page page = layout.getPages().get(pageIndex);
    Size2f pageSize = page.getFormat().getSize();
    int width = Units.mmToPxInt(pageSize.width, zoom);
    int height = Units.mmToPxInt(pageSize.height, zoom);
    WritableImage wim = new WritableImage(width, height);
    Canvas jfxCanvas = new Canvas(width, height);
    GraphicsContext context = jfxCanvas.getGraphicsContext2D();
    context.setFill(Color.WHITE);
    context.fillRect(0, 0, width, height);
    LayoutRenderer.paintToCanvas(layout, pageIndex, zoom, origin, new JfxCanvas(context, pageSize, CanvasFormat.Raster, CanvasDecoration.Interactive, CanvasIntegrity.Perfect));
    jfxCanvas.snapshot(null, wim);
    return wim;
}
Also used : WritableImage(javafx.scene.image.WritableImage) GraphicsContext(javafx.scene.canvas.GraphicsContext) Size2f(com.xenoage.utils.math.geom.Size2f) JfxCanvas(com.xenoage.zong.renderer.javafx.canvas.JfxCanvas) Canvas(javafx.scene.canvas.Canvas) Page(com.xenoage.zong.layout.Page) JfxCanvas(com.xenoage.zong.renderer.javafx.canvas.JfxCanvas)

Aggregations

Size2f (com.xenoage.utils.math.geom.Size2f)1 Page (com.xenoage.zong.layout.Page)1 JfxCanvas (com.xenoage.zong.renderer.javafx.canvas.JfxCanvas)1 Canvas (javafx.scene.canvas.Canvas)1 GraphicsContext (javafx.scene.canvas.GraphicsContext)1 WritableImage (javafx.scene.image.WritableImage)1