Android ColorMatrix brightness matrix contrast matrix black and white matrix

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.