Class WritableImage
- javafx.scene.image.Image
-
- javafx.scene.image.WritableImage
public class WritableImage extends Image
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
Constructors Constructor and Description WritableImage(int width, int height)Construct an empty image of the specified dimensions.WritableImage(PixelReader reader, int width, int height)Construct an image of the specified dimensions, initialized from the indicatedPixelReader.WritableImage(PixelReader reader, int x, int y, int width, int height)Construct an image of the specified dimensions, initialized from the indicated region of thePixelReader.
-
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description PixelWritergetPixelWriter()This method returns aPixelWriterthat provides access to write the pixels of the image.-
Methods inherited from class javafx.scene.image.Image
cancel, errorProperty, exceptionProperty, getException, getHeight, getPixelReader, getProgress, getRequestedHeight, getRequestedWidth, getWidth, heightProperty, isBackgroundLoading, isError, isPreserveRatio, isSmooth, progressProperty, widthProperty
-
-
Constructor Detail
-
WritableImage
public WritableImage(int width, int height)Construct 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 imageThrows:
IllegalArgumentException- if either dimension is negative or zero.
-
WritableImage
public WritableImage(PixelReader reader, int width, int height)Construct an image of the specified dimensions, initialized from the indicatedPixelReader. The image will initially be filled with data returned from thePixelReader. If thePixelReaderaccesses a surface that does not contain the necessary number of pixel rows and columns then anArrayIndexOutOfBoundsExceptionwill 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:
width- the desired width of the writable image and the width of the region to be read from thereaderThrows:
ArrayIndexOutOfBoundsException- if thereaderdoes not access a surface of at least the requested dimensions
-
WritableImage
public WritableImage(PixelReader reader, int x, int y, int width, int height)Construct an image of the specified dimensions, initialized from the indicated region of thePixelReader. The image will initially be filled with data returned from thePixelReaderfor the specified region. If thePixelReaderaccesses a surface that does not contain the necessary number of pixel rows and columns then anArrayIndexOutOfBoundsExceptionwill 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:
x- the X coordinate of the upper left corner of the region to read from thereaderThrows:
ArrayIndexOutOfBoundsException- if thereaderdoes not access a surface containing at least the indicated region
-
-
Method Detail
-
getPixelWriter
public final PixelWriter getPixelWriter()
This method returns aPixelWriterthat provides access to write the pixels of the image.Returns:
the
PixelWriterfor writing pixels to the image
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.