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
Properties declared in class Image
error, exception, height, progress, widthTypePropertyDescriptionfinal ReadOnlyBooleanPropertyIndicates whether an error was detected while loading an image.final ReadOnlyObjectProperty<Exception> The exception which caused image loading to fail.final ReadOnlyDoublePropertyThe image height or0if the image loading fails.final ReadOnlyDoublePropertyThe approximate percentage of image's loading that has been completed.final ReadOnlyDoublePropertyThe image width or0if the image loading fails. -
Constructor Summary
ConstructorsConstructorDescriptionWritableImage(int width, int height) Constructs an empty image of the specified dimensions.WritableImage(PixelBuffer<? extends Buffer> pixelBuffer) Constructs aWritableImageusing 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 PixelWriterThis method returns aPixelWriterthat provides access to write the pixels of the image.Methods declared in class Image
cancel, errorProperty, exceptionProperty, getException, getHeight, getPixelReader, getProgress, getRequestedHeight, getRequestedWidth, getUrl, getWidth, heightProperty, isBackgroundLoading, isError, isPreserveRatio, isSmooth, progressProperty, widthPropertyModifier and TypeMethodDescriptionvoidcancel()Cancels the background loading of this image.final ReadOnlyBooleanPropertyIndicates whether an error was detected while loading an image.final ReadOnlyObjectProperty<Exception> The exception which caused image loading to fail.final ExceptionGets the value of theexceptionproperty.final doubleGets the value of theheightproperty.final PixelReaderThis method returns aPixelReaderthat provides access to read the pixels of the image, if the image is readable.final doubleGets the value of theprogressproperty.final doubleGets the height of the bounding box within which the source image is resized as necessary to fit.final doubleGets the width of the bounding box within which the source image is resized as necessary to fit.final StringgetUrl()Returns the url used to fetch the pixel data contained in the Image instance, if specified in the constructor.final doublegetWidth()Gets the value of thewidthproperty.final ReadOnlyDoublePropertyThe image height or0if the image loading fails.final booleanIndicates whether the image is being loaded in the background.final booleanisError()Gets the value of theerrorproperty.final booleanIndicates whether to preserve the aspect ratio of the original image when scaling to fit the image within the bounding box provided bywidthandheight.final booleanisSmooth()Indicates whether to use a better quality filtering algorithm or a faster one when scaling this image to fit within the bounding box provided bywidthandheight.final ReadOnlyDoublePropertyThe approximate percentage of image's loading that has been completed.final ReadOnlyDoublePropertyThe image width or0if the image loading fails.
-
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 aWritableImageusing the specifiedPixelBuffer. TheBufferprovided by thePixelBufferwill be used directly as the pixel data for this image. ThePixelBuffercan be shared by multipleWritableImages. Images constructed this way are readable usingImage.getPixelReader(), but are not writable usingWritableImage.getPixelWriter().- Parameters:
pixelBuffer- thePixelBufferused to construct this image- Throws:
NullPointerException- ifpixelBufferisnull- 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 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:
reader- thePixelReaderto construct fromwidth- the desired width of the writable image and the width of the region to be read from thereaderheight- the desired height of the desired image and the width of the region to be read from thereader- Throws:
ArrayIndexOutOfBoundsException- if thereaderdoes 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 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:
reader- thePixelReaderto construct fromx- the X coordinate of the upper left corner of the region to read from thereadery- the Y coordinate of the upper left corner of the region to read from thereaderwidth- the desired width of the writable image and the width of the region to be read from thereaderheight- the desired height of the desired image and the width of the region to be read from thereader- Throws:
ArrayIndexOutOfBoundsException- if thereaderdoes not access a surface containing at least the indicated regionIllegalArgumentException- if either dimension is negative or zero.
-
-
Method Details
-
getPixelWriter
This method returns aPixelWriterthat provides access to write the pixels of the image. This method is not supported for images constructed using aPixelBuffer.- Returns:
- the
PixelWriterfor writing pixels to the image - Throws:
UnsupportedOperationException- if this image was created using aPixelBuffer
-