Java Reference
In-Depth Information
Understanding the Image Ops API
The JavaFX Image Ops API allows JavaFX programs to manipulate images at the pixel level. The key to the JavaFX
Image Ops API is a pair of interfaces in the
javafx.scene.image
package:
PixelReader
and
PixelWriter
. You can
obtain a
PixelReader
from a
javafx.scene.image.Image
object. And you can obtain a
PixelWriter
from a
javafx.scene.image.WritableImage
object.
WritableImage
is a subclass of
Image
.
The
PixelReader
interface includes the following public methods:
PixelFormat getPixelFormat()
•
int getArgb(int x, int y)
•
Color getColor(int x, int y)
•
<T extends Buffer> void getPixels(int x, int y, int w, int h,
WritablePixelFormat<T> pixelFormat, T buffer, int scanlineStride)
•
void getPixels(int x, int y, int w, int h, WritablePixelFormat<ByteBuffer>
pixelFormat, byte[] buffer, int offset, int scanlineStride)
•
void getPixels(int x, int y, int w, int h, WritablePixelFormat<IntBuffer>
pixelFormat, int[] buffer, int offset, int scanlineStride)
The
getPixelFormat()
method returns the pixel format of the underlying image. The
getArgb()
method returns
the color of the pixel as an 32-bit integer whose 4 bytes from the most significant to the least significant contains the
ARGB components of the color at the specified pixel. The
getColor()
method returns the color at the specified pixel
as a
Color
object. The
getPixels()
methods take the area of the image specified by the first four parameters
(
x
,
y
,
w
,
h
), read the color of these pixels, and write them to the
buffer
according to the
WritablePixelFormat
, the buffer type,
offset
, and
scanlineStride
.
The
PixelWriter
interface includes the following public methods:
•
PixelFormat getPixelFormat()
•
void setArgb(int x, int y, int argb)
•
void setColor(int x, int y, Color color)
•
<T extends Buffer> void setPixels(int x, int y, int w, int h, PixelFormat<T>
pixelFormat, T buffer, int scanlineStride)
•
void setPixels(int x, int y, int w, int h, PixelFormat<ByteBuffer> pixelFormat,
byte[] buffer, int offset, int scanlineStride)
•
void setPixels(int x, int y, int w, int h, PixelFormat<IntBuffer> pixelFormat,
int[] buffer, int offset, int scanlineStride)
•
void setPixels(int dstx, int dsty, int w, int h, PixelReader reader, int srcx,
int srcy)
The
getPixelFormat()
method returns the pixel format of the underlying
WritableImage
. The
setArgb()
method sets the color of the pixel (
x
,
y
) to
argb
. The
setColor()
method sets the color of the pixel (
x
,
y
) to
color
.
The
setPixels()
methods that take a
pixelFormat
parameter set the colors of the pixels in the area (
x
,
y
,
w
,
h
) to
the values specified in
buffer
, according to the
PixelFormat
, the buffer type,
offset
, and
scanlineStride
. The
setPixels()
method that takes a
PixelReader
sets the colors of the pixels in the area (
dstx
,
dsty
,
w
,
h
) according to
what is available from the
PixelReader
, starting at the pixel (
srcx
,
srcy
).
The
PixelFormat
and
WritablePixelFormat
describe how the color information of each pixel is stored. Possible
types of PixelFormat are described by the enum
PixelFormat.Type
, which has the following declarators:
INT_ARGB_PRE
,
INT_ARGB
,
BYTE_BGRA_PRE
,
BYTE_BGRA
,
BYTE_RGB
,
BYTE_INDEXED
.
•
Search WWH ::
Custom Search