Java 类javafx.scene.SnapshotResult 实例源码

项目:fx-player    文件:PlayList.java   
private void controlSaveSnapshot() {
    MediaView mediaView = videoPane.getMediaView();
    if (mediaView == null) {
        return;
    }
    MediaInfo mediaInfo = currentInfoProperty.getValue();
    if (mediaInfo == null) {
        return;
    }
    final String title = mediaInfo.titleDescProperty().getValue();
    mediaView.snapshot(new Callback<SnapshotResult, Void>() {

        @Override
        public Void call(SnapshotResult result) {
            Image image = result.getImage();
            if (image == null) {
                return null;
            }
            if (!saveSnapshotService.isRunning()) {
                snapshotImageInfoProperty.setValue(new ImageInfo(image, title));
                saveSnapshotService.restart();
            }
            return null;
        }
    }, null, null);
}
项目:Gargoyle    文件:FxUtil.java   
/********************************
 * 작성일 : 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();
}
项目:Gargoyle    文件:FxUtil.java   
public static void printJob(Window window, Node target, BiConsumer<SnapshotResult, ImageView> draw) {
    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 -> {

        draw.accept(param, imageView);

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