Example usage for javafx.scene SnapshotParameters setCamera

List of usage examples for javafx.scene SnapshotParameters setCamera

Introduction

In this page you can find the example usage for javafx.scene SnapshotParameters setCamera.

Prototype

public void setCamera(Camera camera) 

Source Link

Document

Sets the camera to the specified value.

Usage

From source file:be.makercafe.apps.makerbench.editors.JFXMillEditor.java

private void handleExportAsPngFile(ActionEvent e) {

    if (millObject == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There is no geometry !");
        alert.setContentText("Please verify that your code generates a valid CSG object.");
        alert.showAndWait();/*from w w  w.  j a  va2s. co m*/
        return;
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export PNG File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".png")) {
        fName += ".png";
    }

    int snWidth = 1024;
    int snHeight = 1024;

    double realWidth = viewGroup.getBoundsInLocal().getWidth();
    double realHeight = viewGroup.getBoundsInLocal().getHeight();

    double scaleX = snWidth / realWidth;
    double scaleY = snHeight / realHeight;

    double scale = Math.min(scaleX, scaleY);

    PerspectiveCamera snCam = new PerspectiveCamera(false);
    snCam.setTranslateZ(-200);

    SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(scale, scale));
    snapshotParameters.setCamera(snCam);
    snapshotParameters.setDepthBuffer(true);
    snapshotParameters.setFill(Color.TRANSPARENT);

    WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale));

    viewGroup.snapshot(snapshotParameters, snapshot);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName));
    } catch (IOException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There went something wrong writing the file.");
        alert.setContentText(
                "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace.");
        alert.showAndWait();
    }
}

From source file:eu.mihosoft.vrl.fxscad.MainController.java

@FXML
private void onExportAsPngFile(ActionEvent e) {

    if (csgObject == null) {
        Action response = Dialogs.create().title("Error").message("Cannot export PNG. There is no geometry :(")
                .lightweight().showError();

        return;//from w  w w . j a va  2  s. c o  m
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export PNG File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".png")) {
        fName += ".png";
    }

    int snWidth = 1024;
    int snHeight = 1024;

    double realWidth = viewGroup.getBoundsInLocal().getWidth();
    double realHeight = viewGroup.getBoundsInLocal().getHeight();

    double scaleX = snWidth / realWidth;
    double scaleY = snHeight / realHeight;

    double scale = Math.min(scaleX, scaleY);

    PerspectiveCamera snCam = new PerspectiveCamera(false);
    snCam.setTranslateZ(-200);

    SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(scale, scale));
    snapshotParameters.setCamera(snCam);
    snapshotParameters.setDepthBuffer(true);
    snapshotParameters.setFill(Color.TRANSPARENT);

    WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale));

    viewGroup.snapshot(snapshotParameters, snapshot);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName));
    } catch (IOException ex) {
        Logger.getLogger(MainController.class.getName()).log(Level.SEVERE, null, ex);
    }
}

From source file:be.makercafe.apps.makerbench.editors.GCodeEditor.java

private void handleExportAsPngFile(ActionEvent e) {

    if (csgObject == null) {
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There is no geometry !");
        alert.setContentText("Please verify that your code generates a valid CSG object.");
        alert.showAndWait();/*from   ww w  .ja  v a2  s. co  m*/
        return;
    }

    FileChooser fileChooser = new FileChooser();
    fileChooser.setTitle("Export PNG File");
    fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Image files (*.png)", "*.png"));

    File f = fileChooser.showSaveDialog(null);

    if (f == null) {
        return;
    }

    String fName = f.getAbsolutePath();

    if (!fName.toLowerCase().endsWith(".png")) {
        fName += ".png";
    }

    int snWidth = 1024;
    int snHeight = 1024;

    double realWidth = viewGroup.getBoundsInLocal().getWidth();
    double realHeight = viewGroup.getBoundsInLocal().getHeight();

    double scaleX = snWidth / realWidth;
    double scaleY = snHeight / realHeight;

    double scale = Math.min(scaleX, scaleY);

    PerspectiveCamera snCam = new PerspectiveCamera(false);
    snCam.setTranslateZ(-200);

    SnapshotParameters snapshotParameters = new SnapshotParameters();
    snapshotParameters.setTransform(new Scale(scale, scale));
    snapshotParameters.setCamera(snCam);
    snapshotParameters.setDepthBuffer(true);
    snapshotParameters.setFill(Color.TRANSPARENT);

    WritableImage snapshot = new WritableImage(snWidth, (int) (realHeight * scale));

    viewGroup.snapshot(snapshotParameters, snapshot);

    try {
        ImageIO.write(SwingFXUtils.fromFXImage(snapshot, null), "png", new File(fName));
    } catch (IOException ex) {
        Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, null, ex);
        Alert alert = new Alert(AlertType.ERROR);
        alert.setTitle("Oeps an error occured");
        alert.setHeaderText("Cannot export PNG. There went something wrong writing the file.");
        alert.setContentText(
                "Please verify that your file is not read only, is not locked by other user or program, you have enough diskspace.");
        alert.showAndWait();
    }
}