Save Node or Scene to Image in JavaFX 2.0


Even after waiting so many days, the Javafx bug team has not implemented this feature still in this new Javafx General Availability release . So I’ve managed to make blog about this function for javafx. Many javafx enterprises developer may think that javafx is still not useful because they don’t know how to save their graphics component in image format. Developer don’t have a simple api function like sceneToImage() which was provided in javafx script 1.3. Don’t know why ? We developers are that’s why intelligent to find the alternative way. So I also intended to research on this topic.Then started to warmup my hands on keyboard.

We are using some Java apis and JavaFX apis for making these things work. Ok Let’s get started with the class ‘FXImaging’

I’ve commented the codes so that you will understand the use of the function properly. In above class the nodeToImage(),sceneToImage() are the function which help to save your Node or Scene into Image format. The save() function helps to save your bufferedImage from JavaAPI. After saving the image the Node/Scene is being restored to the original stage from where the Node/Scene is being taken. The algorithm of saving Node/Scene is given in the picture below.

Now you can easily save your Node or Scene in the Image format. Below is one of the sample demo of saving the Scene into Image.

Image of Node

Or if you want to make image of whole Scene then use this code:

Image of Scene

It has image like below

Thanks. for watching this blog. You can comment if you have any queries.
Have a good 🙂 day.

12 thoughts on “Save Node or Scene to Image in JavaFX 2.0”

  1. Hello! Cool works!

    But is (will) any possibility to NOT use AWT and Swing?
    As I can imagine, this layers bring additional requirements of time and memory?

  2. Narayan Gopal Maharjan

    Actually it’s just the hack for saving the Node or scene to Image format. The JavaFX team is working on this facility I think this facility will be available on coming version soon

    Thanks.

  3. Pingback: Java desktop links of the week, November 7 | Jonathan Giles

  4. Very nice one..!! Liked it a lot..!! Thank u very much use full to my project as well. Keep it up…, keep doing.

  5. Yes we can send to browser for download as well, but I think you should make your own server and port for listening to the visitor’s computer and send file there by using HTTP headers rules.

Leave a Reply