java.lang.Object
javafx.embed.swing.SwingFXUtils
This class provides utility methods for converting data types between
Swing/AWT and JavaFX formats.
- Since:
- JavaFX 2.2
-
Method Summary
Modifier and TypeMethodDescriptionstatic BufferedImagefromFXImage(Image img, BufferedImage bimg) Snapshots the specified JavaFXImageobject and stores a copy of its pixels into aBufferedImageobject, creating a new object if needed.static WritableImagetoFXImage(BufferedImage bimg, WritableImage wimg) Snapshots the specifiedBufferedImageand stores a copy of its pixels into a JavaFXImageobject, creating a new object if needed.
-
Method Details
-
toFXImage
Snapshots the specifiedBufferedImageand stores a copy of its pixels into a JavaFXImageobject, creating a new object if needed. The returnedImagewill be a static snapshot of the state of the pixels in theBufferedImageat the time the method completes. Further changes to theBufferedImagewill not be reflected in theImage.The optional JavaFX
WritableImageparameter may be reused to store the copy of the pixels. A newImagewill 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- theBufferedImageobject to be convertedwimg- an optionalWritableImageobject that can be used to store the returned pixel data- Returns:
- an
Imageobject representing a snapshot of the current pixels in theBufferedImage. - Since:
- JavaFX 2.2
-
fromFXImage
Snapshots the specified JavaFXImageobject and stores a copy of its pixels into aBufferedImageobject, creating a new object if needed. The method will only convert a JavaFXImagethat is readable as per the conditions on theImage.getPixelReader()method. If theImageis not readable, as determined by itsgetPixelReader()method, then this method will return null. If theImageis a writable, or other dynamic image, then theBufferedImagewill only be set to the current state of the pixels in the image as determined by itsPixelReader. Further changes to the pixels of theImagewill not be reflected in the returnedBufferedImage.The optional
BufferedImageparameter may be reused to store the copy of the pixels. A newBufferedImagewill 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 JavaFXImageto be convertedbimg- an optionalBufferedImageobject that may be used to store the returned pixel data- Returns:
- a
BufferedImagecontaining a snapshot of the JavaFXImage, or null if theImageis not readable. - Since:
- JavaFX 2.2
-