create Color Filter By Color - Android Graphics

Android examples for Graphics:Color Filter

Description

create Color Filter By Color

Demo Code


//package com.java2s;

import android.graphics.ColorMatrixColorFilter;

public class Main {
    public static ColorMatrixColorFilter createColorFilterByColor(int aColor) {
        final int r = (aColor >> 16) & 255;
        final int g = (aColor >> 8) & 255;
        final int b = aColor & 255;
        final float[] array = new float[] { 0, 0, 0, 0, r, 0, 0, 0, 0, g,
                0, 0, 0, 0, b, 0, 0, 0, 1, 0 };
        return new ColorMatrixColorFilter(array);
    }/*from  www.  ja v  a 2 s .  c  o m*/

    public static ColorMatrixColorFilter createColorFilterByColor(
            int aColor, float aAlpha) {
        final int r = (aColor >> 16) & 255;
        final int g = (aColor >> 8) & 255;
        final int b = aColor & 255;
        final float[] array = new float[] { 0, 0, 0, 0, r, 0, 0, 0, 0, g,
                0, 0, 0, 0, b, 0, 0, 0, aAlpha, 0 };
        return new ColorMatrixColorFilter(array);
    }
}

Related Tutorials