get Paint From Color - Android Graphics

Android examples for Graphics:Color

Description

get Paint From Color

Demo Code


//package com.java2s;

import android.graphics.Color;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;

public class Main {
    public static Paint getPaintFromColor(int color) {
        final float[] array = new float[20];
        array[18] = 1;//  w  w  w  .  j  av  a2 s . c o  m
        array[1] = (float) Color.red(color) / 255;
        array[6] = (float) Color.green(color) / 255;
        array[11] = (float) Color.blue(color) / 255;
        final Paint paint = new Paint();
        paint.setColorFilter(new ColorMatrixColorFilter(array));
        return paint;
    }
}

Related Tutorials