# ColorMatrix

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/graphics/ColorMatrix#pubctors)\|[Methods](https://developer.android.com/reference/android/graphics/ColorMatrix#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/graphics/ColorMatrix#inhmethods)  

# ColorMatrix

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/graphics/ColorMatrix "View this page in Kotlin")\|Java

`
public


class
ColorMatrix
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.graphics.ColorMatrix |

<br />

*** ** * ** ***

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 ]
```

<br />

## Summary

|                                                                                                                                        ### Public constructors                                                                                                                                         ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix#ColorMatrix())`() ` Create a new colormatrix initialized to identity (as if reset() had been called).                                                                                                         |
| ` `[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix#ColorMatrix(android.graphics.ColorMatrix))`(`[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix)` src) ` Create a new colormatrix initialized with the specified colormatrix. |
| ` `[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix#ColorMatrix(float[]))`(float[] src) ` Create a new colormatrix initialized with the specified array of values.                                                                                                |

|                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                    ||
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`       | ` `[equals](https://developer.android.com/reference/android/graphics/ColorMatrix#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                                                                                                                                                                                                                                                                    |
| ` final float[]` | ` `[getArray](https://developer.android.com/reference/android/graphics/ColorMatrix#getArray())`() ` Return the array of floats representing this colormatrix.                                                                                                                                                                                                                                                                                                                                                                          |
| ` void`          | ` `[postConcat](https://developer.android.com/reference/android/graphics/ColorMatrix#postConcat(android.graphics.ColorMatrix))`(`[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix)` postmatrix) ` Concat this colormatrix with the specified postmatrix.                                                                                                                                                                                                                                             |
| ` void`          | ` `[preConcat](https://developer.android.com/reference/android/graphics/ColorMatrix#preConcat(android.graphics.ColorMatrix))`(`[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix)` prematrix) ` Concat this colormatrix with the specified prematrix.                                                                                                                                                                                                                                                 |
| ` void`          | ` `[reset](https://developer.android.com/reference/android/graphics/ColorMatrix#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 ``` <br />                                                                                                                                                                                                                                                                              |
| ` void`          | ` `[set](https://developer.android.com/reference/android/graphics/ColorMatrix#set(float[]))`(float[] src) ` Assign the array of floats into this matrix, copying all of its values.                                                                                                                                                                                                                                                                                                                                                    |
| ` void`          | ` `[set](https://developer.android.com/reference/android/graphics/ColorMatrix#set(android.graphics.ColorMatrix))`(`[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix)` src) ` Assign the src colormatrix into this matrix, copying all of its values.                                                                                                                                                                                                                                                 |
| ` void`          | ` `[setConcat](https://developer.android.com/reference/android/graphics/ColorMatrix#setConcat(android.graphics.ColorMatrix,%20android.graphics.ColorMatrix))`(`[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix)` matA, `[ColorMatrix](https://developer.android.com/reference/android/graphics/ColorMatrix)` matB) ` 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. |
| ` void`          | ` `[setRGB2YUV](https://developer.android.com/reference/android/graphics/ColorMatrix#setRGB2YUV())`() ` Set the matrix to convert RGB to YUV                                                                                                                                                                                                                                                                                                                                                                                           |
| ` void`          | ` `[setRotate](https://developer.android.com/reference/android/graphics/ColorMatrix#setRotate(int,%20float))`(int axis, float degrees) ` Set the rotation on a color axis by the specified values.                                                                                                                                                                                                                                                                                                                                     |
| ` void`          | ` `[setSaturation](https://developer.android.com/reference/android/graphics/ColorMatrix#setSaturation(float))`(float sat) ` Set the matrix to affect the saturation of colors.                                                                                                                                                                                                                                                                                                                                                         |
| ` void`          | ` `[setScale](https://developer.android.com/reference/android/graphics/ColorMatrix#setScale(float,%20float,%20float,%20float))`(float rScale, float gScale, float bScale, float aScale) ` Set this colormatrix to scale by the specified values.                                                                                                                                                                                                                                                                                       |
| ` void`          | ` `[setYUV2RGB](https://developer.android.com/reference/android/graphics/ColorMatrix#setYUV2RGB())`() ` Set the matrix to convert from YUV to RGB                                                                                                                                                                                                                                                                                                                                                                                      |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### ColorMatrix

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public ColorMatrix ()
```

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

<br />

### ColorMatrix

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public ColorMatrix (ColorMatrix src)
```

Create a new colormatrix initialized with the specified colormatrix.

<br />

|         Parameters          ||
|-------|----------------------|
| `src` | `ColorMatrix` <br /> |

### ColorMatrix

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public ColorMatrix (float[] src)
```

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

<br />

|      Parameters       ||
|-------|----------------|
| `src` | `float` <br /> |

## Public methods

### equals

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean equals (Object obj)
```

Indicates whether some other object is "equal to" this one.

The`equals`method implements an equivalence relation on non-null object references:

- It is*reflexive* : for any non-null reference value`x`,`x.equals(x)`should return`true`.
- It is*symmetric* : for any non-null reference values`x`and`y`,`x.equals(y)`should return`true`if and only if`y.equals(x)`returns`true`.
- It is*transitive* : for any non-null reference values`x`,`y`, and`z`, if`x.equals(y)`returns`true`and`y.equals(z)`returns`true`, then`x.equals(z)`should return`true`.
- It is*consistent* : for any non-null reference values`x`and`y`, multiple invocations of`x.equals(y)`consistently return`true`or consistently return`false`, provided no information used in`equals`comparisons on the objects is modified.
- For any non-null reference value`x`,`x.equals(null)`should return`false`.

An equivalence relation partitions the elements it operates on into*equivalence classes*; all the members of an equivalence class are equal to each other. Members of an equivalence class are substitutable for each other, at least for some purposes.

<br />

|                             Parameters                              ||
|-------|--------------------------------------------------------------|
| `obj` | `Object`: the reference object with which to compare. <br /> |

|                                         Returns                                          ||
|-----------|-------------------------------------------------------------------------------|
| `boolean` | `true`if this object is the same as the obj argument;`false`otherwise. <br /> |

### getArray

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public final float[] getArray ()
```

Return the array of floats representing this colormatrix.

<br />

|      Returns      ||
|-----------|--------|
| `float[]` | <br /> |

### postConcat

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void postConcat (ColorMatrix postmatrix)
```

Concat this colormatrix with the specified postmatrix.

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

<br />

<br />

|             Parameters             ||
|--------------|----------------------|
| `postmatrix` | `ColorMatrix` <br /> |

### preConcat

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void preConcat (ColorMatrix prematrix)
```

Concat this colormatrix with the specified prematrix.

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

<br />

<br />

|            Parameters             ||
|-------------|----------------------|
| `prematrix` | `ColorMatrix` <br /> |

### reset

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void 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
 
```

<br />

<br />

### set

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void set (float[] src)
```

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

<br />

|      Parameters       ||
|-------|----------------|
| `src` | `float` <br /> |

### set

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void set (ColorMatrix src)
```

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

<br />

|         Parameters          ||
|-------|----------------------|
| `src` | `ColorMatrix` <br /> |

### setConcat

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setConcat (ColorMatrix matA, 
                ColorMatrix matB)
```

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.

<br />

<br />

|          Parameters          ||
|--------|----------------------|
| `matA` | `ColorMatrix` <br /> |
| `matB` | `ColorMatrix` <br /> |

### setRGB2YUV

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setRGB2YUV ()
```

Set the matrix to convert RGB to YUV

<br />

### setRotate

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setRotate (int axis, 
                float degrees)
```

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

<br />

<br />

|        Parameters         ||
|-----------|----------------|
| `axis`    | `int` <br />   |
| `degrees` | `float` <br /> |

### setSaturation

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setSaturation (float sat)
```

Set the matrix to affect the saturation of colors.

<br />

|                                    Parameters                                    ||
|-------|---------------------------------------------------------------------------|
| `sat` | `float`: A value of 0 maps the color to gray-scale. 1 is identity. <br /> |

### setScale

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setScale (float rScale, 
                float gScale, 
                float bScale, 
                float aScale)
```

Set this colormatrix to scale by the specified values.

<br />

|        Parameters        ||
|----------|----------------|
| `rScale` | `float` <br /> |
| `gScale` | `float` <br /> |
| `bScale` | `float` <br /> |
| `aScale` | `float` <br /> |

### setYUV2RGB

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setYUV2RGB ()
```

Set the matrix to convert from YUV to RGB

<br />