Here is the snippet where i save the image with a .png extension:
WritableImage img = rectCanvas.snapshot(new SnapshotParameters(), null);
JFileChooser chooser = new JFileChooser();
chooser.setCurrentDirectory(new File(System.getProperty("user.home")));
int result = chooser.showSaveDialog(null);
if (result == JFileChooser.APPROVE_OPTION) {
try {
File fileToSave = chooser.getSelectedFile();
ImageIO.write(SwingFXUtils.fromFXImage(img, null), "png", fileToSave);
} catch (IOException ex) {
Logger.getLogger(GuiClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
I want .png to be my default file extension. However when i want to save an image to file and open the save dialog i have to enter the file name in the following format: filename.png. How can i get rid of the .png part and make it default?
chooser.getSelectedFile()
? – Hovercraft Full Of Eelschooser.getSelectedFile()
? – Tom