Skip to content
Advertisement

JavaFX – save canvas to png file

I’ve created a simple drawing program which just basically prints pictures on a canvas by choosing from 3 pictures and then the user can save the image that he created and open a previous image , the program works perfectly good , but I’m facing a problem :

  • when I save the image , the image is not being saved as a png ,it’s rather getting saved as a file (not sure though) but even when it’s not being saved as a png , the image is getting saved and the user can open it and it opens as it was saved.

Here’s the code :

JavaScript

Advertisement

Answer

A minimal reproducible example of the problem you are trying to solve could be as simple as :

JavaScript

This makes isolatng the problem and helping way easier.
To overwrite a PNG file you only have to select it with the filechooder.
To create a new file you need to type its name and its extension: name.png
You can have the extension applied automatically by adding an ExtensionFilter to the FileChooser

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement