ColorMatrix
open class ColorMatrix
kotlin.Any | |
↳ | android.graphics.ColorMatrix |
4x5 matrix for transforming the color and alpha components of a Bitmap. The matrix can be passed as single array, and is treated as follows:
[ a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t ]
When applied to a color [R, G, B, A]
, the resulting color is computed as:
R’ = a*R + b*G + c*B + d*A + e; G’ = f*R + g*G + h*B + i*A + j; B’ = k*R + l*G + m*B + n*A + o; A’ = p*R + q*G + r*B + s*A + t;
That resulting color [R’, G’, B’, A’]
then has each channel clamped to the 0
to 255
range.
The sample ColorMatrix below inverts incoming colors by scaling each channel by -1
, and then shifting the result up by 255
to remain in the standard color space.
[ -1, 0, 0, 0, 255, 0, -1, 0, 0, 255, 0, 0, -1, 0, 255, 0, 0, 0, 1, 0 ]
Summary
Public constructors | |
---|---|
Create a new colormatrix initialized to identity (as if reset() had been called). |
|
ColorMatrix(src: FloatArray!) Create a new colormatrix initialized with the specified array of values. |
|
ColorMatrix(src: ColorMatrix!) Create a new colormatrix initialized with the specified colormatrix. |
Public methods | |
---|---|
open Boolean | |
FloatArray! |
getArray() Return the array of floats representing this colormatrix. |
open Unit |
postConcat(postmatrix: ColorMatrix!) Concat this colormatrix with the specified postmatrix. |
open Unit |
preConcat(prematrix: ColorMatrix!) Concat this colormatrix with the specified prematrix. |
open Unit |
reset() Set this colormatrix to identity: [ 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 |
open Unit |
set(src: ColorMatrix!) Assign the src colormatrix into this matrix, copying all of its values. |
open Unit |
set(src: FloatArray!) Assign the array of floats into this matrix, copying all of its values. |
open Unit |
setConcat(matA: ColorMatrix!, matB: ColorMatrix!) Set this colormatrix to the concatenation of the two specified colormatrices, such that the resulting colormatrix has the same effect as applying matB and then applying matA. |
open Unit |
Set the matrix to convert RGB to YUV |
open Unit |
Set the rotation on a color axis by the specified values. |
open Unit |
setSaturation(sat: Float) Set the matrix to affect the saturation of colors. |
open Unit |
Set this colormatrix to scale by the specified values. |
open Unit |
Set the matrix to convert from YUV to RGB |
Public constructors
ColorMatrix
ColorMatrix()
Create a new colormatrix initialized to identity (as if reset() had been called).
ColorMatrix
ColorMatrix(src: FloatArray!)
Create a new colormatrix initialized with the specified array of values.
ColorMatrix
ColorMatrix(src: ColorMatrix!)
Create a new colormatrix initialized with the specified colormatrix.
Public methods
equals
open fun equals(other: Any?): Boolean
Parameters | |
---|---|
obj |
the reference object with which to compare. |
Return | |
---|---|
Boolean |
true if this object is the same as the obj argument; false otherwise. |
getArray
fun getArray(): FloatArray!
Return the array of floats representing this colormatrix.
postConcat
open fun postConcat(postmatrix: ColorMatrix!): Unit
Concat this colormatrix with the specified postmatrix.
This is logically the same as calling setConcat(postmatrix, this);
preConcat
open fun preConcat(prematrix: ColorMatrix!): Unit
Concat this colormatrix with the specified prematrix.
This is logically the same as calling setConcat(this, prematrix);
reset
open fun reset(): Unit
Set this colormatrix to identity:
[ 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
set
open fun set(src: ColorMatrix!): Unit
Assign the src colormatrix into this matrix, copying all of its values.
set
open fun set(src: FloatArray!): Unit
Assign the array of floats into this matrix, copying all of its values.
setConcat
open fun setConcat(
matA: ColorMatrix!,
matB: ColorMatrix!
): Unit
Set this colormatrix to the concatenation of the two specified colormatrices, such that the resulting colormatrix has the same effect as applying matB and then applying matA.
It is legal for either matA or matB to be the same colormatrix as this.
setRotate
open fun setRotate(
axis: Int,
degrees: Float
): Unit
Set the rotation on a color axis by the specified values.
axis=0
correspond to a rotation around the RED color axis=1
correspond to a rotation around the GREEN color axis=2
correspond to a rotation around the BLUE color
setSaturation
open fun setSaturation(sat: Float): Unit
Set the matrix to affect the saturation of colors.
Parameters | |
---|---|
sat |
Float: A value of 0 maps the color to gray-scale. 1 is identity. |
setScale
open fun setScale(
rScale: Float,
gScale: Float,
bScale: Float,
aScale: Float
): Unit
Set this colormatrix to scale by the specified values.
setYUV2RGB
open fun setYUV2RGB(): Unit
Set the matrix to convert from YUV to RGB