What is Color Matrix ?
Color Matrix is a 4x5 matrix (4 Rows and 5 Columns 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 the0
to255
range.The sample ColorMatrix below inverts incoming colors by scaling each channel by
-1
, and then shifting the result up by255
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 ]In Android, we uses floatArray to describe the color matrix.