Implementation of the filter effect under Android

Source: Internet
Author: User

Implementation of the filter effect under Android

Filter filter color has been implemented, the simple version can be implemented by the following code 3 parameters of black and white, red, green ... 7 Kinds of filtering (7 combinations of RGB).

Theoretically, it can be filtered to any color. You can adjust the ratio of the blend results.

public void Drawbitmap (canvas canvas, Bitmap Bitmap, Boolean R, Boolean g, Boolean B) {
ColorMatrix cm = new ColorMatrix ();
float[] m = Cm.getarray ();
Setcolorfiltermatrix (M, R, G, b);
Paint pt = new paint ();
Pt.setcolorfilter (new Colormatrixcolorfilter (cm));
Canvas.drawbitmap (bitmap, 0, 0, PT);
}

public void Setcolorfiltermatrix (float[] m, Boolean R, Boolean g, Boolean B) {
Final float R = 0.213f;
Final float G = 0.715f;
Final float B = 0.072f;

M[0] = 0;
M[6] = 0;
M[12] = 0;

if (r) {
M[0] = R; M[1] = G; M[2] = B;
}
if (g) {
M[5] = R; M[6] = G; M[7] = B;
}
if (b) {
M[10] = R; M[11] = G; M[12] = B;
}
}

Implementation of the filter effect under Android

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.