Java Color Blend blend(Color c1, Color c2)

Here you can find the source of blend(Color c1, Color c2)

Description

Blend 2 colors equally.

License

Open Source License

Parameter

Parameter Description
c1 first color
c2 second color

Return

a new Color which is c1 and c2 blended in equal amounts

Declaration

public static Color blend(Color c1, Color c2) 

Method Source Code


//package com.java2s;
// it under the terms of the GNU General Public License as published by

import java.awt.Color;

public class Main {
    /** Blend 2 colors equally.
    @param c1 first color//from  ww  w . j  a v a  2  s.  co  m
    @param c2 second color
    @return a new Color which is c1 and c2 blended in equal amounts
    */
    public static Color blend(Color c1, Color c2) {
        return new Color((c1.getRed() + c2.getRed()) / 2, (c1.getGreen() + c2.getGreen()) / 2,
                (c1.getBlue() + c2.getBlue()) / 2);
    }

    /** Blend 2 colors in unequal amounts.  The fractions f1, f2 indicate
    how much of each color to use; it's assumed that f1+f2=1.0 (or
    to within Java's tolerance).
        
    <p>For example, the call blend(Color.red, 0.1f, Color.white, 0.9f)
    returns a new Color which is 10% red and 90% white.</p>
        
    @param c1 first color
    @param f1 fraction of first color to use
    @param c2 second color
    @param f2 fraction of second color to use
    @return a new Color which is c1 and c2 blended in unequal amounts
    */
    public static Color blend(Color c1, float f1, Color c2, float f2) {
        return new Color((int) (f1 * c1.getRed() + f2 * c2.getRed()),
                (int) (f1 * c1.getGreen() + f2 * c2.getGreen()), (int) (f1 * c1.getBlue() + f2 * c2.getBlue()));
    }
}

Related

  1. alphaBlend(final Color src, final Color dst)
  2. blend(Color a, Color b)
  3. blend(Color a, Color b, double val)
  4. blend(Color c0, Color c1)
  5. blend(Color c1, Color c2)
  6. blend(Color c1, Color c2, double v)
  7. blend(Color cFrom, Color cTo, float factor)
  8. blend(Color col1, Color col2, float weight1)
  9. blend(Color color1, Color color2, float ratio)