Class PixelFormat<T extends Buffer>
java.lang.Object
javafx.scene.image.PixelFormat<T>
- Type Parameters:
T
- the type of buffer that stores the pixel data. OnlyByteBuffer
andIntBuffer
are used.
- Direct Known Subclasses:
WritablePixelFormat
A
PixelFormat
object defines the layout of data for a pixel of
a given format.- Since:
- JavaFX 2.2
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
An enum describing the in-array storage format of a single pixel managed by aPixelFormat
. -
Method Summary
Modifier and TypeMethodDescriptionstatic PixelFormat
<ByteBuffer> createByteIndexedInstance
(int[] colors) Creates aPixelFormat
instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of non-premultiplied color values in theINT_ARGB
format.static PixelFormat
<ByteBuffer> createByteIndexedPremultipliedInstance
(int[] colors) Creates aPixelFormat
instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of premultiplied color values in theINT_ARGB_PRE
format.abstract int
Reads pixel data from the buffer at the specified coordinates and converts it to a 32-bit integer representation of the color in theINT_ARGB
format.static WritablePixelFormat
<ByteBuffer> Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.static WritablePixelFormat
<ByteBuffer> Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.static PixelFormat
<ByteBuffer> Returns aPixelFormat
instance describing a pixel layout with the pixels stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.static WritablePixelFormat
<IntBuffer> Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.static WritablePixelFormat
<IntBuffer> Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.getType()
Returns the enum representing the storage format of the pixels managed by thisPixelFormat
object.abstract boolean
Returns true iff the color components decoded (or encoded) by this format are pre-multiplied by the alpha component for more efficient blending calculations.abstract boolean
Returns true iff thisPixelFormat
object can convert color information into a pixel representation.
-
Method Details
-
getIntArgbInstance
Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in 32-bit integers with the non-premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x]; int alpha = ((pixel >> 24) & 0xff); int red = ((pixel >> 16) & 0xff); int green = ((pixel >> 8) & 0xff); int blue = ((pixel >> ) & 0xff);
- Returns:
- a
WritabelPixelFormat<IntBuffer>
describing the indicated pixel format
-
getIntArgbPreInstance
Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in 32-bit integers with the premultiplied components stored in order, from MSb to LSb: alpha, red, green, blue.Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x]; int alpha = ((pixel >> 24) & 0xff); int red = ((pixel >> 16) & 0xff); int green = ((pixel >> 8) & 0xff); int blue = ((pixel >> ) & 0xff);
- Returns:
- a
WritabelPixelFormat<IntBuffer>
describing the indicated pixel format
-
getByteBgraInstance
Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in adjacent bytes with the non-premultiplied components stored in order of increasing index: blue, green, red, alpha.Pixels in this format can be decoded using the following sample code:
int i = rowstart + x * 4; int blue = (array[i+0] & 0xff); int green = (array[i+1] & 0xff); int red = (array[i+2] & 0xff); int alpha = (array[i+3] & 0xff);
- Returns:
- a
WritablePixelFormat<ByteBuffer>
describing the indicated pixel format
-
getByteBgraPreInstance
Returns aWritablePixelFormat
instance describing a pixel layout with the pixels stored in adjacent bytes with the premultiplied components stored in order of increasing index: blue, green, red, alpha.Pixels in this format can be decoded using the following sample code:
int i = rowstart + x * 4; int blue = (array[i+0] & 0xff); int green = (array[i+1] & 0xff); int red = (array[i+2] & 0xff); int alpha = (array[i+3] & 0xff);
- Returns:
- a
WritablePixelFormat<ByteBuffer>
describing the indicated pixel format
-
getByteRgbInstance
Returns aPixelFormat
instance describing a pixel layout with the pixels stored in adjacent bytes with the color components stored in order of increasing index: red, green, blue.Pixels in this format can be decoded using the following sample code:
int i = rowstart + x * 3; int red = (array[i+0] & 0xff); int green = (array[i+1] & 0xff); int blue = (array[i+2] & 0xff);
- Returns:
- a
PixelFormat<ByteBuffer>
describing the indicated pixel format
-
createByteIndexedPremultipliedInstance
Creates aPixelFormat
instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of premultiplied color values in theINT_ARGB_PRE
format.Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x] & 0xff; int argb = colors[pixel]; int alpha = ((argb >> 24) & 0xff); int red = ((argb >> 16) & 0xff); int green = ((argb >> 8) & 0xff); int blue = ((argb ) & 0xff);
- Parameters:
colors
- anint[]
array of 32-bit color values in theINT_ARGB_PRE
format- Returns:
- a
PixelFormat<ByteBuffer>
describing the indicated pixel format with the specified list of premultiplied colors
-
createByteIndexedInstance
Creates aPixelFormat
instance describing a pixel layout with the pixels stored as single bytes representing an index into the specified lookup table of non-premultiplied color values in theINT_ARGB
format.Pixels in this format can be decoded using the following sample code:
int pixel = array[rowstart + x] & 0xff; int argb = colors[pixel]; int alpha = ((argb >> 24) & 0xff); int red = ((argb >> 16) & 0xff); int green = ((argb >> 8) & 0xff); int blue = ((argb ) & 0xff);
- Parameters:
colors
- anint[]
array of 32-bit color values in theINT_ARGB
format- Returns:
- a
PixelFormat<ByteBuffer>
describing the indicated pixel format with the specified list of non-premultiplied colors
-
getType
Returns the enum representing the storage format of the pixels managed by thisPixelFormat
object.- Returns:
- the
Type
enum of the pixels
-
isWritable
public abstract boolean isWritable()Returns true iff thisPixelFormat
object can convert color information into a pixel representation.- Returns:
- true iff this
PixelFormat
can convert colors to pixel data
-
isPremultiplied
public abstract boolean isPremultiplied()Returns true iff the color components decoded (or encoded) by this format are pre-multiplied by the alpha component for more efficient blending calculations.- Returns:
- true iff the managed color components are premultiplied by alpha
-
getArgb
Reads pixel data from the buffer at the specified coordinates and converts it to a 32-bit integer representation of the color in theINT_ARGB
format. The 32-bit integer will contain the 4 color components in separate 8-bit fields in ARGB order from the most significant byte to the least significant byte. The buffer should be positioned to the start of the pixel data such thatbuf.get(0)
would return the pixel information for the pixel at coordinates(0, 0)
. ThescanlineStride
parameter defines the distance from the pixel data at the start of one row to the pixel data at the start of the immediately following row at the next higher Y coordinate. Usually,scanlineStride
is the same as the width of the image multiplied by the number of data elements per pixel (1 for the case of the integer and indexed formats, or 3 or 4 in the case of the byte formats), but some images may have further padding between rows for alignment or other purposes.The color components can be extracted from the returned integer using the following sample code:
int alpha = ((retval >> 24) & 0xff); int red = ((retval >> 16) & 0xff); int green = ((retval >> 8) & 0xff); int blue = ((retval ) & 0xff);
- Parameters:
buf
- the buffer of pixel datax
- the X coordinate of the pixel to be ready
- the Y coordinate of the pixel to be readscanlineStride
- the number of buffer elements between the start of adjacent pixel rows in the buffer- Returns:
- a 32-bit value with the color of the pixel in a format
similar to the
INT_ARGB
pixel format
-