Class WritableImage
java.lang.Object
javafx.scene.image.Image
javafx.scene.image.WritableImage
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
-
Property Summary
-
Constructor Summary
ConstructorDescriptionWritableImage
(int width, int height) Constructs an empty image of the specified dimensions.WritableImage
(PixelBuffer<? extends Buffer> pixelBuffer) Constructs aWritableImage
using the specifiedPixelBuffer
.WritableImage
(PixelReader reader, int width, int height) Constructs an image of the specified dimensions, initialized from the indicatedPixelReader
.WritableImage
(PixelReader reader, int x, int y, int width, int height) Constructs an image of the specified dimensions, initialized from the indicated region of thePixelReader
. -
Method Summary
Modifier and TypeMethodDescriptionfinal PixelWriter
This method returns aPixelWriter
that provides access to write the pixels of the image.Methods declared in class javafx.scene.image.Image
cancel, errorProperty, exceptionProperty, getException, getHeight, getPixelReader, getProgress, getRequestedHeight, getRequestedWidth, getUrl, getWidth, heightProperty, isBackgroundLoading, isError, isPreserveRatio, isSmooth, progressProperty, widthProperty
-
Constructor Details
-
WritableImage
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
- the desired width of the writable imageheight
- the desired height of the desired image- Throws:
IllegalArgumentException
- if either dimension is negative or zero.
-
WritableImage
Constructs aWritableImage
using the specifiedPixelBuffer
. TheBuffer
provided by thePixelBuffer
will be used directly as the pixel data for this image. ThePixelBuffer
can be shared by multipleWritableImage
s. Images constructed this way are readable usingImage.getPixelReader()
, but are not writable usingWritableImage.getPixelWriter()
.- Parameters:
pixelBuffer
- thePixelBuffer
used to construct this image- Throws:
NullPointerException
- ifpixelBuffer
isnull
- Since:
- 13
-
WritableImage
Constructs an image of the specified dimensions, initialized from the indicatedPixelReader
. The image will initially be filled with data returned from thePixelReader
. If thePixelReader
accesses a surface that does not contain the necessary number of pixel rows and columns then anArrayIndexOutOfBoundsException
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
- thePixelReader
to construct fromwidth
- the desired width of the writable image and the width of the region to be read from thereader
height
- the desired height of the desired image and the width of the region to be read from thereader
- Throws:
ArrayIndexOutOfBoundsException
- if thereader
does not access a surface of at least the requested dimensionsIllegalArgumentException
- if either dimension is negative or zero.
-
WritableImage
Constructs an image of the specified dimensions, initialized from the indicated region of thePixelReader
. The image will initially be filled with data returned from thePixelReader
for the specified region. If thePixelReader
accesses a surface that does not contain the necessary number of pixel rows and columns then anArrayIndexOutOfBoundsException
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
- thePixelReader
to construct fromx
- the X coordinate of the upper left corner of the region to read from thereader
y
- the Y coordinate of the upper left corner of the region to read from thereader
width
- the desired width of the writable image and the width of the region to be read from thereader
height
- the desired height of the desired image and the width of the region to be read from thereader
- Throws:
ArrayIndexOutOfBoundsException
- if thereader
does not access a surface containing at least the indicated regionIllegalArgumentException
- if either dimension is negative or zero.
-
-
Method Details
-
getPixelWriter
This method returns aPixelWriter
that provides access to write the pixels of the image. This method is not supported for images constructed using aPixelBuffer
.- Returns:
- the
PixelWriter
for writing pixels to the image - Throws:
UnsupportedOperationException
- if this image was created using aPixelBuffer
-