APIdia Launch Partner
Top Description Fields Constructors Methods
javafx.scene.image

public Class WritableImage

extends Image
Class Inheritance
Imports
com.sun.javafx.geom.Rectangle, com.sun.javafx.tk.ImageLoader, .PlatformImage, .Toolkit, javafx.beans.NamedArg, javafx.beans.property.ReadOnlyObjectProperty, javafx.scene.paint.Color, java.nio.Buffer, .ByteBuffer, .IntBuffer, java.util.Objects

The WritableImage class 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.
Since
JavaFX 2.2

Field Summary

Modifier and TypeField and Description
private PixelBuffer<? extends Buffer>
private ImageLoader
private PixelWriter

Constructor Summary

AccessConstructor and Description
public
WritableImage(int
the desired width of the writable image
width
,
int
the desired height of the desired image
height
)

Constructs an empty image of the specified dimensions.

public
WritableImage(PixelBuffer<? extends Buffer>
the PixelBuffer used to construct this image
pixelBuffer
)

Constructs a WritableImage using the specified PixelBuffer.

public
WritableImage(PixelReader
the PixelReader to construct from
reader
,
int
the desired width of the writable image and the width of the region to be read from the reader
width
,
int
the desired height of the desired image and the width of the region to be read from the reader
height
)

Constructs an image of the specified dimensions, initialized from the indicated PixelReader.

public
WritableImage(PixelReader
the PixelReader to construct from
reader
,
int
the X coordinate of the upper left corner of the region to read from the reader
x
,
int
the Y coordinate of the upper left corner of the region to read from the reader
y
,
int
the desired width of the writable image and the width of the region to be read from the reader
width
,
int
the desired height of the desired image and the width of the region to be read from the reader
height
)

Constructs an image of the specified dimensions, initialized from the indicated region of the PixelReader.

Method Summary

Modifier and TypeMethod and Description
pack-priv void
public final PixelWriter

Returns:

the PixelWriter for writing pixels to the image
getPixelWriter
()

This method returns a PixelWriter that provides access to write the pixels of the image.

private Object
pack-priv boolean
isAnimation()

Overrides javafx.scene.image.Image.isAnimation.

Indicates whether image is animated.

private void
pack-priv boolean
private static PixelBuffer<? extends Buffer>
validatePixelBuffer(PixelBuffer<? extends Buffer> pixelBuffer)

Inherited from javafx.scene.image.Image:
acc_platformImagePropertycanceldisposeerrorPropertyexceptionPropertyfromPlatformImagegetExceptiongetHeightgetInputSourcegetPixelReadergetPlatformImagegetProgressgetRequestedHeightgetRequestedWidthgetUrlgetWidthgetWritablePlatformImageheightPropertyisBackgroundLoadingisErrorisPreserveRatioisSmoothpixelsDirtyprogressPropertysetPlatformImagesetProgresswidthProperty

Field Detail

pixelBufferback to summary
private PixelBuffer<? extends Buffer> pixelBuffer
tkImageLoaderback to summary
private ImageLoader tkImageLoader
writerback to summary
private PixelWriter writer

Constructor Detail

WritableImageback to summary
public WritableImage(int width, int height)

Constructs an empty image of the specified dimensions. The image will initially be filled with transparent pixels. Images constructed this way will always be readable and writable so the corresponding getPixelReader() and getPixelWriter() will always return valid objects. The dimensions must both be positive numbers (> 0).

Parameters
width:int

the desired width of the writable image

height:int

the desired height of the desired image

Exceptions
IllegalArgumentException:
if either dimension is negative or zero.
WritableImageback to summary
public WritableImage(PixelBuffer<? extends Buffer> pixelBuffer)

Constructs a WritableImage using the specified PixelBuffer. The Buffer provided by the PixelBuffer will be used directly as the pixel data for this image. The PixelBuffer can be shared by multiple WritableImages. Images constructed this way are readable using Image.getPixelReader(), but are not writable using WritableImage.getPixelWriter().

Parameters
pixelBuffer:PixelBuffer<? extends Buffer>

the PixelBuffer used to construct this image

Exceptions
NullPointerException:
if pixelBuffer is null
Since
13
WritableImageback to summary
public WritableImage(PixelReader reader, int width, int height)

Constructs an image of the specified dimensions, initialized from the indicated PixelReader. The image will initially be filled with data returned from the PixelReader. If the PixelReader accesses a surface that does not contain the necessary number of pixel rows and columns then an ArrayIndexOutOfBoundsException will be thrown. Images constructed this way will always be readable and writable so the corresponding getPixelReader() and getPixelWriter() will always return valid objects. The dimensions must both be positive numbers (> 0).

Parameters
reader:PixelReader

the PixelReader to construct from

width:int

the desired width of the writable image and the width of the region to be read from the reader

height:int

the desired height of the desired image and the width of the region to be read from the reader

Exceptions
ArrayIndexOutOfBoundsException:
if the reader does not access a surface of at least the requested dimensions
IllegalArgumentException:
if either dimension is negative or zero.
WritableImageback to summary
public WritableImage(PixelReader reader, int x, int y, int width, int height)

Constructs an image of the specified dimensions, initialized from the indicated region of the PixelReader. The image will initially be filled with data returned from the PixelReader for the specified region. If the PixelReader accesses a surface that does not contain the necessary number of pixel rows and columns then an ArrayIndexOutOfBoundsException will be thrown. Images constructed this way will always be readable and writable so the corresponding getPixelReader() and getPixelWriter() will always return valid objects. The dimensions must both be positive numbers (> 0).

Parameters
reader:PixelReader

the PixelReader to construct from

x:int

the X coordinate of the upper left corner of the region to read from the reader

y:int

the Y coordinate of the upper left corner of the region to read from the reader

width:int

the desired width of the writable image and the width of the region to be read from the reader

height:int

the desired height of the desired image and the width of the region to be read from the reader

Exceptions
ArrayIndexOutOfBoundsException:
if the reader does not access a surface containing at least the indicated region
IllegalArgumentException:
if either dimension is negative or zero.

Method Detail

bufferDirtyback to summary
pack-priv void bufferDirty(Rectangle rect)
getPixelWriterback to summary
public final PixelWriter getPixelWriter()

This method returns a PixelWriter that provides access to write the pixels of the image. This method is not supported for images constructed using a PixelBuffer.

Returns:PixelWriter

the PixelWriter for writing pixels to the image

Exceptions
UnsupportedOperationException:
if this image was created using a PixelBuffer
getTkImageLoaderback to summary
private Object getTkImageLoader()
isAnimationback to summary
pack-priv boolean isAnimation()

Overrides javafx.scene.image.Image.isAnimation.

Doc from javafx.scene.image.Image.isAnimation.

Indicates whether image is animated.

Annotations
@Override
loadTkImageback to summary
private void loadTkImage(Object loader)
pixelsReadableback to summary
pack-priv boolean pixelsReadable()

Overrides javafx.scene.image.Image.pixelsReadable.

Annotations
@Override
validatePixelBufferback to summary
private static PixelBuffer<? extends Buffer> validatePixelBuffer(PixelBuffer<? extends Buffer> pixelBuffer)