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;
}
Aggregations