java.lang.Object
javafx.embed.swing.SwingFXUtils
public class SwingFXUtils extends Object
This class provides utility methods for converting data types between
Swing/AWT and JavaFX formats.
- Since:
- JavaFX 2.2
-
Method Summary
Modifier and Type Method Description static BufferedImage
fromFXImage(Image img, BufferedImage bimg)
Snapshots the specified JavaFXImage
object and stores a copy of its pixels into aBufferedImage
object, creating a new object if needed.static WritableImage
toFXImage(BufferedImage bimg, WritableImage wimg)
Snapshots the specifiedBufferedImage
and stores a copy of its pixels into a JavaFXImage
object, creating a new object if needed.
-
Method Details
-
toFXImage
Snapshots the specifiedBufferedImage
and stores a copy of its pixels into a JavaFXImage
object, creating a new object if needed. The returnedImage
will be a static snapshot of the state of the pixels in theBufferedImage
at the time the method completes. Further changes to theBufferedImage
will not be reflected in theImage
.The optional JavaFX
WritableImage
parameter may be reused to store the copy of the pixels. A newImage
will be created if the supplied object is null, is too small or of a type which the image pixels cannot be easily converted into.- Parameters:
bimg
- theBufferedImage
object to be convertedwimg
- an optionalWritableImage
object that can be used to store the returned pixel data- Returns:
- an
Image
object representing a snapshot of the current pixels in theBufferedImage
. - Since:
- JavaFX 2.2
-
fromFXImage
Snapshots the specified JavaFXImage
object and stores a copy of its pixels into aBufferedImage
object, creating a new object if needed. The method will only convert a JavaFXImage
that is readable as per the conditions on theImage.getPixelReader()
method. If theImage
is not readable, as determined by itsgetPixelReader()
method, then this method will return null. If theImage
is a writable, or other dynamic image, then theBufferedImage
will only be set to the current state of the pixels in the image as determined by itsPixelReader
. Further changes to the pixels of theImage
will not be reflected in the returnedBufferedImage
.The optional
BufferedImage
parameter may be reused to store the copy of the pixels. A newBufferedImage
will be created if the supplied object is null, is too small or of a type which the image pixels cannot be easily converted into.- Parameters:
img
- the JavaFXImage
to be convertedbimg
- an optionalBufferedImage
object that may be used to store the returned pixel data- Returns:
- a
BufferedImage
containing a snapshot of the JavaFXImage
, or null if theImage
is not readable. - Since:
- JavaFX 2.2
-