# ColorMatrix class? RSS

## 2 replies

Last post Apr 03, 2007 05:18 AM by atsofttech

None

0 Points

11 Posts

### ColorMatrix class?

Apr 09, 2005 06:43 PM|nightcoder|LINK

I read some articles which use ColorMatrix recently. What does color matrix mean? I think it modifies each pixel's value. I don't get what each column and row of the matrix mean. Any article or info regarding this? Thanks

Member

20 Points

657 Posts

### Re: ColorMatrix class?

Apr 11, 2005 10:28 AM|Qnnn|LINK

From manual:

Defines a 5x5 matrix that contains the coordinates for the RGBA space. Several methods of the ImageAttributes class adjust image colors by using a color matrix. Not inheritable.

The matrix coefficients constitute a 5x5 linear transformation that is used for transforming ARGB homogeneous values. For example, an ARGB vector represented as alpha, red, green, blue, and w, where w is always 1.

Gunnar Peipman

-- General Protection Fault
-- Illegal Page Fault
-- Not My Fault

Member

382 Points

264 Posts

### Re: ColorMatrix class?

Apr 03, 2007 05:18 AM|atsofttech|LINK

This may help you to understand better. Taken from http://vbforums.com/showthread.php?s=8fb475c05b2efd3b456e56e83a614a69&threadid=258872

/*
* ColorMatrix Explanation:
*   1   0   0  0  0
*   0   1   0  0  0
*   0   0   1  0  0
*   0   0   0  1  0
* .37 .15 .07  0  1
*
* r = (r*1) + (g*0) + (b*0) + (a*0) + (1*.37) = r + .37
* g = (r*0) + (g*1) + (b*0) + (a*0) + (1*.15) = g + .15
* b = (r*0) + (g*0) + (b*1) + (a*0) + (1*.07) = b + .07
* a = (r*0) + (g*0) + (b*0) + (a*1) + (1*0)   = a
*
* Max value for each r,g,b,a value is 1 which means 255. The 5th column is useless except for the last row (5,5).
* Last row is for translation
* Another explanation:
* RED                 rR gR bR aR 0
* GREEN              rG gG bG aG 0
* BLUE                rB gB bB aB 0
* ALPHA              rA gA bA aA 0
* TRANSFORM      fR fG fB fA F
*
* This will convert (R, G, B, A) to:
* R = (R*rR) + (G*gR) + (B*bR) + (A*aR) +   (F*fR)
* G = (R*rG) + (G*gG) + (B*bG) + (A*aG) +   (F*fG)
* B = (R*rB) + (G*gB) + (B*bB) + (A*aB) +   (F*fB)
* A = (R*rA) + (G*gA) + (B*bA) + (A*aA) +   (F*fB)
*/

Everything is possible!