The color matrix M is a matrix of 5*4, and the color matrix m in android is stored in a one-dimensional array m=[a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t] way.
Each line of the matrix is:
R[a b c D E]
G[f G h i j]
B[k l m N O]
A[p Q R S t]
The RGBA value of the image is stored in a 5*1 color component matrix C, in order to change the color effect of a picture, only need to change the image of the color component matrix.
In the Colormatrixfilter filtering time, the incoming parameter ColorMatrix, the first should be postconcat brightness matrix:
floatLum = (Brightness- -) *2*255*0.01f; Matrix.Set(New float[] {1,0,0,0, Lum,0,1,0,0, Lum,0,0,1,0, Lum,0,0,0,1,0});
Then postconcat the contrast matrix:
//scale is 1 for normal mode, [0, 1] for reducing contrast, [1, 1 + factor] for increasing contrast float Scale=1;if(Contrast < -) { Scale= contrast/ -F }Else if(Contrast > -) { Scale= (Contrast- -) / -f *2.5F +1; }floatLum = the* Brightness/ -* (1F- Scale); Cm.set (Newfloat[] { Scale,0,0,0, Lum,0, Scale,0,0, Lum,0,0, Scale,0, Lum,0,0,0,1,0});
Finally, multiply some effect matrices, such as the Black and white matrix:
floatA =0.3086f* the;floatb =0.6094f* the;floatc =0.0820f* the;floatLum =- the* threshold; ColorMatrix matrix =NewColorMatrix (); Matrix.Set(New float[] {A, B, C,0, Lum, A, B, C,0, Lum, A, B, C,0, Lum,0,0,0,1,0});
Image effects: Erosion and fill: watermarks are different effects.
A watermark is a picture printed on a graph. The watermark effect can be added as a washout, which is often used to make background images. If the watermark is not selected for erosion, then the watermark should be the original image.
The erosion effect is achieved by adjusting the contrast and brightness of the picture.
Android colormatrix brightness matrix contrast matrix black and white matrix