import flash.filter.ColorMatrixFilter;
颜色矩阵:var arr:Array ;
R G B A Off
R 1 0 0 0 0
G 0 1 0 0 0
B 0 0 1 0 0
A 0 0 0 1 0
上面这个矩阵就是颜色变换矩阵,颜色变换矩阵是一个四行五列的矩阵。RGBA值算法如下(MC原先的RGBA值用oldR,oldG,oldB,oldA来表示):
R : newR = arr[0] * oldR + arr[1] * oldG + arr[2] * oldB + arr[3] * oldA + arr[4] ;
G : newG = arr[5] * oldR + arr[6] * oldG + arr[7] * oldB + arr[8] * oldA + arr[9] ;
B : newB = arr[10] * oldR + arr[11] * oldG + arr[12] * oldB + arr[13] * oldA + arr[14] ;
A : newA = arr[15] * oldR + arr[16] * oldG + arr[17] * oldB + arr[18] * oldA + arr[19] ;
如何利用颜色矩阵:
(1) R G B A Off
R 1 0 0 0 50
G 0 1 0 0 0
B 0 0 1 0 0
A 0 0 0 1 0
| R通道的偏移量设为50。即让R通道的R值+50 |
(2) R G B A Off
R 1 0 0 0 0
G 0 1 0 0 0
B 0 0 2 0 0
A 0 0 0 1 0
| B通道翻倍 |
(3) R G B A Off
R 1 0 0 0 0
G 1 0 0 0 0
B 0 0 1 0 0
A 0 0 0 1 0
| 让原图的G值等于原图的R值 |
(4) R G B A Off R G B A Off
R 1 0 0 0 30 R 1.2 0 0 0 0
G 1 0 0 0 30 G 0 1.2 0 0 0
B 0 0 1 0 30 B 0 0 1.2 0 0
A 0 0 0 1 0 或者 A 0 0 0 1 0
| 改变原图的亮度 |
(5) R G B A Off
R .33 .33 .33 0 0
G .33 .33 .33 0 0
B .33 .33 .33 0 0
A 0 0 0 1 0
| 将原图变为灰度图,在相册的应用中经常会使用到 |
具体程序:
var colorMat:Array = [ 1,0,0,0,100,
0,1,0,0,0,
0,0,1,0,0,
0,0,0,1,0 ];
var mc:MovieClip = new MovieClip();
var cmFilter:ColorMatrixFilter = new ColorMatrixFilter(colorMat);
mc.filters = [cmFilter];