Friday Aug 24, 2012

Take a snapshot with JavaFX!

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
About

Blog about Java technology documentation and news about Java releases.

Search

Categories
Archives
« August 2012 »
SunMonTueWedThuFriSat
   
1
2
3
4
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
21
22
23
25
26
27
28
29
30
31
 
       
Today