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.