Take a snapshot with JavaFX!
- by user12610255
JavaFX 2.2 has a "snapshot" feature that enables you to take a picture of any node or scene.
Take a look at the API Documentation and you will find new snapshot methods in the javafx.scene.Scene class.
The most basic version has the following signature:
public WritableImage snapshot(WritableImage image)
The WritableImage class (also introduced in JavaFX 2.2) lives in the javafx.scene.image package, and
represents a custom graphical image that is constructed from pixels supplied by the application.
In fact, there are 5 new classes in javafx.scene.image:
PixelFormat: Defines the layout of data for a pixel of a given format.
WritablePixelFormat: Represents a pixel format that can store
full colors and so can be used as a destination format to write pixel data from an arbitrary image.
PixelReader: Defines methods for retrieving the pixel data from an Image or other surface containing pixels.
PixelWriter: Defines methods for writing the pixel data of a WritableImage or other surface containing writable pixels.
WritableImage: Represents a custom graphical image that is constructed from pixels supplied by
the application, and possibly from PixelReader objects from any number of sources,
including images read from a file or URL.
The API documentation contains lots of information, so go investigate and have fun with these useful new classes!
-- Scott Hommel