Java 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

Colorblend(Color color1, Color color2, float ratio)
Blend two colors.
float ir = (float) 1.0 - ratio;
float rgb1[] = new float[3];
float rgb2[] = new float[3];
color1.getColorComponents(rgb1);
color2.getColorComponents(rgb2);
return new Color(rgb1[0] * ratio + rgb2[0] * ir, rgb1[1] * ratio + rgb2[1] * ir,
        rgb1[2] * ratio + rgb2[2] * ir);
Colorblend(Color color1, Color color2, int factor)
Blend two colors.
if (color2 == null)
    return color1;
if (factor <= 0)
    return color1;
if (factor >= 256)
    return color2;
if (color1 == null)
    return color2;
...
Colorblend(Color origin, Color over)
Blends two colors to create a new color.
if (over == null) {
    return origin;
if (origin == null) {
    return over;
int a = over.getAlpha();
int rb = (((over.getRGB() & 0x00ff00ff) * (a + 1)) + ((origin.getRGB() & 0x00ff00ff) * (0xff - a)))
...
Colorblend(Color pColor, Color pOther)
Blends two colors half and half, to create a tone in between.
return new Color(blend(pColor.getRGB(), pOther.getRGB()), true);
Colorblend(double factor, Color color1, Color color2)
Blend together two colors, using the specified factor to indicate the weight given to the first color.
int r = (int) Math.round(factor * color1.getRed() + (1.0 - factor) * color2.getRed());
int g = (int) Math.round(factor * color1.getGreen() + (1.0 - factor) * color2.getGreen());
int b = (int) Math.round(factor * color1.getBlue() + (1.0 - factor) * color2.getBlue());
return new Color(r, g, b);
Colorblend(final Color color1, final Color color2, final double ratio)
blend
final float r = (float) ratio;
final float ir = (float) 1.0 - r;
final float rgb1[] = new float[3];
final float rgb2[] = new float[3];
color1.getColorComponents(rgb1);
color2.getColorComponents(rgb2);
float red = rgb1[0] * r + rgb2[0] * ir;
float green = rgb1[1] * r + rgb2[1] * ir;
...
Colorblend(final Color first, final Color second, final float alpha)
Blends two colors with a given alpha value.
final int red = (int) ((first.getRed() * alpha) + second.getRed() * (1 - alpha));
final int green = (int) ((first.getGreen() * alpha) + second.getGreen() * (1 - alpha));
final int blue = (int) ((first.getBlue() * alpha) + second.getBlue() * (1 - alpha));
return new Color(red, green, blue);
ColorblendAlpha(Color under, Color over)
blend Alpha
float rgb1[] = new float[3];
float rgb2[] = new float[3];
under.getColorComponents(rgb1);
over.getColorComponents(rgb2);
int ualpha = under.getAlpha();
int oalpha = over.getAlpha();
float u = ualpha / 255f;
float o = oalpha / 255f;
...
Colorblendcol(Color in, Color bl)
blendcol
int f1 = bl.getAlpha();
int f2 = 255 - bl.getAlpha();
return (new Color(((in.getRed() * f2) + (bl.getRed() * f1)) / 255,
        ((in.getGreen() * f2) + (bl.getGreen() * f1)) / 255,
        ((in.getBlue() * f2) + (bl.getBlue() * f1)) / 255, in.getAlpha()));
ColorblendColor(Color clOne, Color clTwo, double amount)
Calculate a brighter or darker version of the originalColor.
float fAmount = (float) amount;
float fInverse = 1.0f - fAmount;
float afOne[] = new float[3];
clOne.getColorComponents(afOne);
float afTwo[] = new float[3];
clTwo.getColorComponents(afTwo);
float afResult[] = new float[3];
afResult[0] = afOne[0] * fAmount + afTwo[0] * fInverse;
...