``` 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 ] ``` This is often used as input for [ColorFilter.colorMatrix] and applied at draw time through [Paint.colorFilter]' /> ``` 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 ] ``` This is often used as input for [ColorFilter.colorMatrix] and applied at draw time through [Paint.colorFilter]'>

ColorMatrix

Class

Common
value class ColorMatrix(
    val values: FloatArray =
        floatArrayOf(1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f, 0f, 0f, 0f, 0f, 1f, 0f)
)

4x5 matrix for transforming the color and alpha components of a source. 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:

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


This is often used as input for `ColorFilter.colorMatrix` and applied at draw time through
`Paint.colorFilter`


## Functions

```kotlin
inline operator fun get(row: Int, column: Int) = values[(row * 5) + column]

Obtain an instance of the matrix value at the given row and column. ColorMatrix follows row major order in regards to the positions of matrix values within the flattened array. That is, content order goes from left to right then top to bottom as opposed to column major order.

Parameters

rowRow index to query the ColorMatrix value. Range is from 0 to 3 as ColorMatrix is represented as a 4 x 5 matrix
columnColumn index to query the ColorMatrix value. Range is from 0 to 4 as ColorMatrix is represented as a 4 x 5 matrix
inline operator fun set(row: Int, column: Int, v: Float)

Set the matrix value at the given row and column. ColorMatrix follows row major order in regards to the positions of matrix values within the flattened array. That is, content order goes from left to right then top to bottom as opposed to column major order.

Parameters

rowRow index to query the ColorMatrix value. Range is from 0 to 3 as ColorMatrix is represented as a 4 x 5 matrix
columnColumn index to query the ColorMatrix value. Range is from 0 to 4 as ColorMatrix is represented as a 4 x 5 matrix
vvalue to update at the given row and column
inline fun 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
fun set(src: ColorMatrix)

Assign the src colormatrix into this matrix, copying all of its values.

operator fun timesAssign(colorMatrix: ColorMatrix)

Multiply this matrix by colorMatrix and assign the result to this matrix.

fun setToSaturation(sat: Float)

Set the matrix to affect the saturation of colors.

Parameters

satA value of 0 maps the color to gray-scale. 1 is identity.
fun setToScale(redScale: Float, greenScale: Float, blueScale: Float, alphaScale: Float)

Create a ColorMatrix with the corresponding scale parameters for the red, green, blue and alpha axes

Parameters

redScaleDesired scale parameter for the red channel
greenScaleDesired scale parameter for the green channel
blueScaleDesired scale parameter for the blue channel
alphaScaleDesired scale parameter for the alpha channel
fun setToRotateRed(degrees: Float)

Rotate by degrees along the red color axis

fun setToRotateGreen(degrees: Float)

Rotate by degrees along the green color axis

fun setToRotateBlue(degrees: Float)

Rotate by degrees along the blue color axis

fun convertRgbToYuv()

Set the matrix to convert RGB to YUV

fun convertYuvToRgb()

Set the matrix to convert from YUV to RGB