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