Android ColorMatrix brightness matrix contrast matrix black/white matrix, androidcolormatrix

Source: Internet
Author: User

Android ColorMatrix brightness matrix contrast matrix black/white matrix, androidcolormatrix

Color matrix M is a 5*4 matrix. In android, the color matrix M is 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] storage.

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. To change the color effect of an image, you only need to change the color component matrix of the image.

When filtering ColorMatrixFilter, the input ColorMatrix parameter should first be postConcat brightness matrix:

        float lum = (brightness - 50) * 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});

PostConcat contrast matrix:

// The normal mode when scale is 1, [0, 1] to reduce contrast, [1, 1 + factor] To Increase contrast float scale = 1; if (contrast <50) {scale = contrast/50f;} else if (contrast> 50) {scale = (contrast-50)/50f * 2.5f + 1 ;} float lum = 256 * brightness/100 * (1f-scale); cm. set (new float [] {scale, 0, 0, 0, lum, 0, scale, 0, 0, lum, 0, 0, scale, 0, lum, 0, 0, 0, 1, 0 });

Then multiply some effect matrices, such as the black and white matrices:

        float a = 0.3086f * 256;        float b = 0.6094f * 256;        float c = 0.0820f * 256;        float lum = -256 * threshold;        ColorMatrix matrix = new ColorMatrix();        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 filling methods: watermarks are different effects.
A watermark is used to print a graph on a graph. Erosion can be added to the watermark effect, which is usually used as a background image. If no erosion is selected, the source image is used as the watermark.
The erosion effect is achieved by adjusting the contrast and brightness of the image.

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.