Learning Android Development

Android Image Color Change With ColorMatrix

Easily change the color of an image with ColorMatrix, explained with examples

--

Picture by Denise Chan on Unsplash

If we want to change color of an image, is it complicated? It is very easy if we understand the use of ColorMatrix to filter it. I’ll describe this in detail and provide various useful examples of it here.

For illustration, I’ll use the picture of the colorful roses.

ColorMatrix Mathematically

ColorMatrix is a data class that contains a four rows x five columns array of values.

Mathematically, if the array is as below:

[ a, b, c, d, e,
f, g, h, i, j,
k, l, m, n, o,
p, q, r, s, t ]

Then the new color [R’G'B'A'] applied to the image is a mathematic operation on the original color [RGBA] as below:

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;

--

--