public class ColorMatrix extends Object
PixelMap object.
This class provides a 4 x 5 matrix of floating-point numbers to implement translation, scaling,
or saturation adjustment on color vectors.
The following is an example of ColorMatrix instance:
M = [ m00, m01, m02, m03, m04,
m10, m11, m12, m13, m14,
m20, m21, m22, m23, m24,
m30, m31, m32, m33, m34 ]
A color vector is represented as [R, G, B, A, 1].
R, G, and B indicate the color value, and A indicates the alpha value.
By adding vector 1, you will be able to represent translation of the color vector by matrix multiplication.
After the transformation, the color vector is as follows:
R = m00*R + m01*G + m02*B + m03*A + m04
G = m10*R + m11*G + m12*B + m13*A + m14
B = m20*R + m21*G + m22*B + m23*A + m24
A = m30*R + m31*G + m32*B + m33*A + m34 | 构造器 | 说明 |
|---|---|
ColorMatrix() |
Default constructor used to create a
ColorMatrix instance. |
ColorMatrix(float[] srcMatrix) |
A constructor used to create a row major
ColorMatrix instance and initialize it using a specified array. |
ColorMatrix(ColorMatrix srcMatrix) |
A constructor used to create and initialize a
ColorMatrix instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
float[] |
getMatrix() |
Obtains the floating point array of a
colorMatrix instance. |
void |
modify(float[] src) |
Modifies this
ColorMatrix. |
void |
postConcat(ColorMatrix colorMatrix) |
Post-multiplies this
ColorMatrix by a specified color matrix, and saves the result to this
ColorMatrix. |
void |
postTranslate(float redOffset,
float greenOffset,
float blueOffset,
float alphaOffset) |
Sets a
ColorMatrix instance to translate according to a specified value. |
void |
reset() |
Resets a
colorMatrix instance to an identity matrix. |
void |
setMatrix(float[] colorArray) |
Changes a
ColorMatrix instance. |
void |
setSaturation(float saturation) |
Sets the saturation of a
ColorMatrix instance. |
void |
setScale(float redScale,
float greenScale,
float blueScale,
float alphaScale) |
Sets a
ColorMatrix instance to scale according to a specified value. |
public ColorMatrix()
ColorMatrix instance.
This method creates a ColorMatrix instance and initializes it to an identity matrix.
public ColorMatrix(float[] srcMatrix)
ColorMatrix instance and initialize it using a specified array.public ColorMatrix(ColorMatrix srcMatrix)
ColorMatrix instance.public final float[] getMatrix()
colorMatrix instance.colorMatrix instance.public void reset()
colorMatrix instance to an identity matrix.
The identity matrix is defined as follows:
[ 1 0 0 0 0 - red vector 0 1 0 0 0 - green vector 0 0 1 0 0 - blue vector 0 0 0 1 0 ] - alpha vector
public void setMatrix(float[] colorArray)
ColorMatrix instance.
The values in the floating point array are copied to the ColorMatrix
instance to change the color matrix.
colorArray - Indicates the floating point array, whose length is 20.public void setScale(float redScale,
float greenScale,
float blueScale,
float alphaScale)
ColorMatrix instance to scale according to a specified value.redScale - Indicates the scaling coefficient of red.greenScale - Indicates the scaling coefficient of green.blueScale - Indicates the scaling coefficient of blue.alphaScale - Indicates the scaling coefficient of alpha value.public void postTranslate(float redOffset,
float greenOffset,
float blueOffset,
float alphaOffset)
ColorMatrix instance to translate according to a specified value.redOffset - Indicates the offset of red.greenOffset - Indicates the offset of green.blueOffset - Indicates the offset of blue.alphaOffset - Indicates the offset of alpha value.public void setSaturation(float saturation)
ColorMatrix instance.
The saturation of the ColorMatrix instance can be set to a specified value.
saturation - Indicates the saturation value, which ranges from 0 to 1.0.
The value 1.0 indicates the identity matrix.public void modify(float[] src)
ColorMatrix.src - Indicates the array of values used to modify this ColorMatrix.public void postConcat(ColorMatrix colorMatrix)
ColorMatrix by a specified color matrix, and saves the result to this
ColorMatrix.colorMatrix - Indicates the color matrix for post-multiplication.