Added in API level 1

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).

Create a new colormatrix initialized with the specified array of values.

Create a new colormatrix initialized with the specified colormatrix.

Public methods
open Boolean
equals(other: Any?)

FloatArray!

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

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

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

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
setRotate(axis: Int, degrees: Float)

Set the rotation on a color axis by the specified values.

open Unit

Set the matrix to affect the saturation of colors.

open Unit
setScale(rScale: Float, gScale: Float, bScale: Float, aScale: Float)

Set this colormatrix to scale by the specified values.

open Unit

Set the matrix to convert from YUV to RGB

Public constructors

ColorMatrix

Added in API level 1
ColorMatrix()

Create a new colormatrix initialized to identity (as if reset() had been called).

ColorMatrix

Added in API level 1
ColorMatrix(src: FloatArray!)

Create a new colormatrix initialized with the specified array of values.

ColorMatrix

Added in API level 1
ColorMatrix(src: ColorMatrix!)

Create a new colormatrix initialized with the specified colormatrix.

Public methods

equals

Added in API level 1
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

Added in API level 1
fun getArray(): FloatArray!

Return the array of floats representing this colormatrix.

postConcat

Added in API level 1
open fun postConcat(postmatrix: ColorMatrix!): Unit

Concat this colormatrix with the specified postmatrix.

This is logically the same as calling setConcat(postmatrix, this);

preConcat

Added in API level 1
open fun preConcat(prematrix: ColorMatrix!): Unit

Concat this colormatrix with the specified prematrix.

This is logically the same as calling setConcat(this, prematrix);

reset

Added in API level 1
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

Added in API level 1
open fun set(src: ColorMatrix!): Unit

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

set

Added in API level 1
open fun set(src: FloatArray!): Unit

Assign the array of floats into this matrix, copying all of its values.

setConcat

Added in API level 1
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.

setRGB2YUV

Added in API level 1
open fun setRGB2YUV(): Unit

Set the matrix to convert RGB to YUV

setRotate

Added in API level 1
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

Added in API level 1
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

Added in API level 1
open fun setScale(
    rScale: Float,
    gScale: Float,
    bScale: Float,
    aScale: Float
): Unit

Set this colormatrix to scale by the specified values.

setYUV2RGB

Added in API level 1
open fun setYUV2RGB(): Unit

Set the matrix to convert from YUV to RGB