Issue
I want to save my canvas with javafx without implement the showDialog, I can do it with the showDialog but I want to delete it.
public void exportCanvasToPNG(String fileName) {
// face = Canvase
if (face != null) {
WritableImage img = face.snapshot(new SnapshotParameters(), null);
FileChooser fChooser = new FileChooser();
fChooser.setTitle("Sauvegarde preview");
fChooser.setInitialFileName(fileName);
fChooser.setInitialDirectory(dir);
fChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("Fichier PNG", "*.png"));
// selectedFile = File
selectedFile = fChooser.showSaveDialog(stage);
try {
if (selectedFile != null) {
ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", selectedFile);
}
} catch (IOException e) {
e.printStackTrace();
}
}
}``
Solution
public void exportCanvasToPNG(String fileName) {
// face = Canvas
if (face != null) {
WritableImage img = face.snapshot(new SnapshotParameters(), null);
try {
File outputFile = new File("FaceSnapshot.png");
ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", outputFile);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Answered By - swpalmer
Answer Checked By - Robin (JavaFixing Admin)