Android examples for Graphics:Color RGB Value
Take a color as input, multiply each of the rgb components and return the new color that results from this.
//package com.java2s; public class Main { /**// w w w. j ava2 s . c o m * Max value for the alpha channel in 32 bit argb. Used for bit * manipulations of the colors. */ public static final int ALPHA_MASK = 0xff000000; /** * Max value for the red channel in 32 bit argb. Used for bit manipulations * of the colors. */ public static final int RED_MASK = 0xff0000; /** * Max value for the green channel in 32 bit argb. Used for bit * manipulations of the colors. */ public static final int GREEN_MASK = 0xff00; /** * Max value for the blue channel in 32 bit argb. Used for bit manipulations * of the colors. */ public static final int BLUE_MASK = 0xff; /** * Take a color as input, multiply each of the rgb components by * mSecondaryColorStrength and return the new color that results from this. * * @param color the primary color to pick rgb values from. * @param secondaryColorStrength controls how much of the Primary color is * left in the Secondary color. * @return the secondary color. */ public static int getSecondaryColorFromPrimaryColor(int color, double secondaryColorStrength) { // Retain the alpha channel return ((color & ALPHA_MASK) + ((int) ((color & RED_MASK) * secondaryColorStrength) & RED_MASK) + ((int) ((color & GREEN_MASK) * secondaryColorStrength) & GREEN_MASK) + ((int) ((color & BLUE_MASK) * secondaryColorStrength) & BLUE_MASK)); } }