Class PixelBuffer<T extends Buffer>

java.lang.Object
javafx.scene.image.PixelBuffer<T>
Type Parameters:
T - the type of Buffer that stores the pixel data. Only ByteBuffer and IntBuffer are supported.

public class PixelBuffer<T extends Buffer> extends Object
The 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);
Since:
13
See Also: