Android Utililty Methods Color Blend

List of utility methods to do Color Blend

Description

The list of methods to do Color Blend are organized into topic(s).

Method

intscreenBlendTwoColors(int c1, int c2)
Blend of color c1 and c2 by applying f(c1, c2) = 1 - (1 - c1) * (1 - c2) per channel.
double a1 = Color.alpha(c1) / ((double) CHANNEL_MAX);
double r1 = Color.red(c1) / ((double) CHANNEL_MAX);
double g1 = Color.green(c1) / ((double) CHANNEL_MAX);
double b1 = Color.blue(c1) / ((double) CHANNEL_MAX);
double a2 = Color.alpha(c2) / ((double) CHANNEL_MAX);
double r2 = Color.red(c2) / ((double) CHANNEL_MAX);
double g2 = Color.green(c2) / ((double) CHANNEL_MAX);
double b2 = Color.blue(c2) / ((double) CHANNEL_MAX);
...
int[]createGrayGradient1()
create Gray Gradient
int[] c = new int[3];
int f = -20;
c[0] = toARGB(255, 90 + f, 90 + f, 90 + f);
c[1] = toARGB(255, 80 + f, 80 + f, 80 + f);
c[2] = toARGB(255, 70 + f, 70 + f, 70 + f);
return c;
int[]createGrayGradient2()
create Gray Gradient
int[] c = new int[3];
int f = -40;
c[0] = toARGB(255, 190 + f, 190 + f, 190 + f);
c[1] = toARGB(255, 185 + f, 185 + f, 185 + f);
c[2] = toARGB(255, 160 + f, 160 + f, 160 + f);
return c;
int[]createGrayGradient3()
create Gray Gradient
int[] c = new int[3];
int f = -40;
c[0] = toARGB(0, 160 + f, 160 + f, 160 + f);
c[1] = toARGB(255, 185 + f, 185 + f, 185 + f);
c[2] = toARGB(0, 160 + f, 160 + f, 160 + f);
return c;
int[]createGreenGradient()
create Green Gradient
int[] colorArray = new int[5];
int alpha = 160;
colorArray[0] = toARGB(alpha, 0, 95, 0);
colorArray[1] = toARGB(alpha, 0, 95, 0);
colorArray[2] = toARGB(alpha, 0, 110, 0);
colorArray[3] = toARGB(alpha, 0, 115, 0);
colorArray[4] = toARGB(alpha, 0, 120, 0);
return colorArray;
...
ColorMatrixColorFiltercreateRGBColorFilter(int red, int green, int blue)
create RGB Color Filter
final float[] array = new float[] { 0, 0, 0, 0, red, 0, 0, 0, 0,
        green, 0, 0, 0, 0, blue, 0, 0, 0, 1, 0 };
return new ColorMatrixColorFilter(array);
ColorMatrixColorFiltercreateRGBColorFilter(int red, int green, int blue, float alpha)
create RGB Color Filter
final float[] array = new float[] { 0, 0, 0, 0, red, 0, 0, 0, 0,
        green, 0, 0, 0, 0, blue, 0, 0, 0, alpha, 0 };
return new ColorMatrixColorFilter(array);
ColorMatrixColorFiltercreateColorChangeFilter( int newColor)
create Color Change Filter
final int r = (newColor >> 16) & 255;
final int g = (newColor >> 8) & 255;
final int b = newColor & 255;
float rRatio = ((float) r) / 255.0f;
float gRatio = ((float) g) / 255.0f;
float bRatio = ((float) b) / 255.0f;
final float[] array = new float[] { rRatio, 0, 0, 0, 0, 0, gRatio,
        0, 0, 0, 0, 0, bRatio, 0, 0, 0, 0, 0, 1, 0 };
...
ColorMatrixColorFiltercreateColorFilterByAlpha( float alpha)
create Color Filter By Alpha
final float[] array = new float[] { 1, 0, 0, 0, 0, 0, 1, 0, 0, 0,
        0, 0, 1, 0, 0, 0, 0, 0, alpha, 0 };
return new ColorMatrixColorFilter(array);
ColorMatrixColorFiltercreateColorFilterByColor(int color)
create Color Filter By Color
final int r = (color >> 16) & 255;
final int g = (color >> 8) & 255;
final int b = color & 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);