Buffer that stores the pixel data.
Only ByteBuffer and IntBuffer are supported.
PixelBuffer class represents pixel data that is constructed from
a java.nio.Buffer supplied by the application.
A WritableImage can use this PixelBuffer directly without copying the pixel data.
This PixelBuffer can be shared among multiple WritableImages.
Pixel data should be stored either in an IntBuffer using a PixelFormat of type
INT_ARGB_PRE or in a ByteBuffer using a PixelFormat of type BYTE_BGRA_PRE.
When the Buffer is updated using the PixelBuffer.updateBuffer method,
all WritableImages that were created using this PixelBuffer are redrawn.
Example code that shows how to create a PixelBuffer:
// Creating a PixelBuffer using BYTE_BGRA_PRE pixel format.
ByteBuffer byteBuffer = ByteBuffer.allocateDirect(width * height * 4);
PixelFormat<ByteBuffer> pixelFormat = PixelFormat.getByteBgraPreInstance();
PixelBuffer<ByteBuffer> pixelBuffer = new PixelBuffer<>(width, height, byteBuffer, pixelFormat);
Image img = new WritableImage(pixelBuffer);
// Creating a PixelBuffer using INT_ARGB_PRE pixel format.
IntBuffer intBuffer = IntBuffer.allocate(width * height);
PixelFormat<IntBuffer> pixelFormat = PixelFormat.getIntArgbPreInstance();
PixelBuffer<IntBuffer> pixelBuffer = new PixelBuffer<>(width, height, intBuffer, pixelFormat);
Image img = new WritableImage(pixelBuffer);
WritableImage#WritableImage(PixelBuffer)
| Modifier and Type | Field and Description |
|---|---|
| private final T | |
| private final int | |
| private final List | |
| private final PixelFormat | |
| private final int |
| Access | Constructor and Description |
|---|---|
| public | PixelBuffer(int
width in pixels of this width, int PixelBufferheight in pixels of this height, T PixelBufferthe buffer that stores the pixel data buffer, PixelFormat<T> the format of pixels in the pixelFormat)bufferConstructs a |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | |
| private void | |
| public T | |
| public int | |
| public PixelFormat | Returns: thePixelFormat of this PixelBufferReturns the |
| public int | |
| public void | updateBuffer(Callback<PixelBuffer<T>, Rectangle2D>
the callback)Callback method that updates the bufferInvokes the specified |
| buffer | back to summary |
|---|---|
| private final T buffer | |
| height | back to summary |
|---|---|
| private final int height | |
| imageRefs | back to summary |
|---|---|
| private final List<WeakReference<WritableImage>> imageRefs | |
| pixelFormat | back to summary |
|---|---|
| private final PixelFormat<T> pixelFormat | |
| width | back to summary |
|---|---|
| private final int width | |
| PixelBuffer | back to summary |
|---|---|
| public PixelBuffer(int width, int height, T buffer, PixelFormat<T> pixelFormat) Constructs a The constructor does not allocate memory to store the pixel data. The application must provide
a buffer with sufficient memory for the combination of dimensions
| |
| addImage | back to summary |
|---|---|
| pack-priv void addImage(WritableImage image) | |
| bufferDirty | back to summary |
|---|---|
| private void bufferDirty(Rectangle rect) | |
| getBuffer | back to summary |
|---|---|
| public T getBuffer() Returns the
| |
| getHeight | back to summary |
|---|---|
| public int getHeight() Returns the
| |
| getPixelFormat | back to summary |
|---|---|
| public PixelFormat Returns the
| |
| getWidth | back to summary |
|---|---|
| public int getWidth() Returns the
| |
| updateBuffer | back to summary |
|---|---|
| public void updateBuffer(Callback<PixelBuffer<T>, Rectangle2D> callback) Invokes the specified This method must be called on the JavaFX Application Thread. Example code that shows how to use this method:
| |