get Color for each of its R G B values - Android Graphics

Android examples for Graphics:Color RGB Value

Description

get Color for each of its R G B values

Demo Code


//package com.java2s;

public class Main {
    /**//from  w  w  w .j a v a2  s .c  o m
     *
     * @param color   getResources().getColor(R.color.xxx)
     * @return rgb
     */
    public static int[] getColorRGB(int color) {
        return new int[] { R(color), G(color), B(color) };
    }

    public static int R(int color) {
        return (color >> 16) & 0xFF;
    }

    public static int G(int color) {
        return (color >> 8) & 0xFF;
    }

    /**
     *
     * @param color getResources().getColor(R.color.xxx)
     * @return
     */
    public static int B(int color) {
        return color & 0xFF;
    }
}

Related Tutorials