APIdia Launch Partner
Top Description Constructors Methods
javafx.embed.swing

public Class SwingFXUtils

extends Object
Class Inheritance
Imports
java.awt.AlphaComposite, .Graphics2D, java.awt.image.BufferedImage, .DataBufferInt, .SampleModel, .SinglePixelPackedSampleModel, java.nio.IntBuffer, javafx.scene.image.Image, .PixelFormat, .PixelReader, .PixelWriter, .WritableImage, .WritablePixelFormat, javafx.scene.paint.Color

This class provides utility methods for converting data types between Swing/AWT and JavaFX formats.
Since
JavaFX 2.2

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
private static boolean
checkFXImageOpaque(PixelReader pr, int iw, int ih)

public static BufferedImage

Returns:

a BufferedImage containing a snapshot of the JavaFX Image, or null if the Image is not readable.
fromFXImage
(Image
the JavaFX Image to be converted
img
,
BufferedImage
an optional BufferedImage object that may be used to store the returned pixel data
bimg
)

Snapshots the specified JavaFX Image object and stores a copy of its pixels into a BufferedImage object, creating a new object if needed.

private static WritablePixelFormat<IntBuffer>
getAssociatedPixelFormat(BufferedImage
the BufferedImage that will be used as a destination for a PixelReader<IntBuffer>#getPixels() operation.
bimg
)

Determine the appropriate WritablePixelFormat type that can be used to transfer data into the indicated BufferedImage.

pack-priv static int
getBestBufferedImageType(PixelFormat<?>
the PixelFormat of the source FX Image
fxFormat
,
BufferedImage
an optional existing BufferedImage to be used for storage if it is compatible, or null
bimg
,
boolean isOpaque)

Determine the optimal BufferedImage type to use for the specified fxFormat allowing for the specified bimg to be used as a potential default storage space if it is not null and is compatible.

public static WritableImage

Returns:

an Image object representing a snapshot of the current pixels in the BufferedImage.
toFXImage
(BufferedImage
the BufferedImage object to be converted
bimg
,
WritableImage
an optional WritableImage object that can be used to store the returned pixel data
wimg
)

Snapshots the specified BufferedImage and stores a copy of its pixels into a JavaFX Image object, creating a new object if needed.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

SwingFXUtilsback to summary
private SwingFXUtils()

Method Detail

checkFXImageOpaqueback to summary
private static boolean checkFXImageOpaque(PixelReader pr, int iw, int ih)
fromFXImageback to summary
public static BufferedImage fromFXImage(Image img, BufferedImage bimg)

Snapshots the specified JavaFX Image object and stores a copy of its pixels into a BufferedImage object, creating a new object if needed. The method will only convert a JavaFX Image that is readable as per the conditions on the Image.getPixelReader() method. If the Image is not readable, as determined by its getPixelReader() method, then this method will return null. If the Image is a writable, or other dynamic image, then the BufferedImage will only be set to the current state of the pixels in the image as determined by its PixelReader. Further changes to the pixels of the Image will not be reflected in the returned BufferedImage.

The optional BufferedImage parameter may be reused to store the copy of the pixels. A new BufferedImage 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:Image

the JavaFX Image to be converted

bimg:BufferedImage

an optional BufferedImage object that may be used to store the returned pixel data

Returns:BufferedImage

a BufferedImage containing a snapshot of the JavaFX Image, or null if the Image is not readable.

Since
JavaFX 2.2
getAssociatedPixelFormatback to summary
private static WritablePixelFormat<IntBuffer> getAssociatedPixelFormat(BufferedImage bimg)

Determine the appropriate WritablePixelFormat type that can be used to transfer data into the indicated BufferedImage.

Parameters
bimg:BufferedImage

the BufferedImage that will be used as a destination for a PixelReader<IntBuffer>#getPixels() operation.

getBestBufferedImageTypeback to summary
pack-priv static int getBestBufferedImageType(PixelFormat<?> fxFormat, BufferedImage bimg, boolean isOpaque)

Determine the optimal BufferedImage type to use for the specified fxFormat allowing for the specified bimg to be used as a potential default storage space if it is not null and is compatible.

Parameters
fxFormat:PixelFormat<?>

the PixelFormat of the source FX Image

bimg:BufferedImage

an optional existing BufferedImage to be used for storage if it is compatible, or null

toFXImageback to summary
public static WritableImage toFXImage(BufferedImage bimg, WritableImage wimg)

Snapshots the specified BufferedImage and stores a copy of its pixels into a JavaFX Image object, creating a new object if needed. The returned Image will be a static snapshot of the state of the pixels in the BufferedImage at the time the method completes. Further changes to the BufferedImage will not be reflected in the Image.

The optional JavaFX WritableImage parameter may be reused to store the copy of the pixels. A new Image 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:BufferedImage

the BufferedImage object to be converted

wimg:WritableImage

an optional WritableImage object that can be used to store the returned pixel data

Returns:WritableImage

an Image object representing a snapshot of the current pixels in the BufferedImage.

Since
JavaFX 2.2