Java Color Blend blend(Color c1, Color c2)

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

Description

Blends the two supplied colors.

License

Open Source License

Return

a color halfway between the two colors.

Declaration

public static final Color blend(Color c1, Color c2) 

Method Source Code


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

import java.awt.Color;

public class Main {
    /**/*from  ww w.ja  va  2s .  co  m*/
     * Blends the two supplied colors.
     *
     * @return a color halfway between the two colors.
     */
    public static final Color blend(Color c1, Color c2) {
        return new Color((c1.getRed() + c2.getRed()) >> 1, (c1.getGreen() + c2.getGreen()) >> 1,
                (c1.getBlue() + c2.getBlue()) >> 1);
    }

    /**
     * Blends the two supplied colors, using the supplied percentage
     * as the amount of the first color to use.
     *
     * @param firstperc The percentage of the first color to use, from 0.0f
     * to 1.0f inclusive.
     */
    public static final Color blend(Color c1, Color c2, float firstperc) {
        float p2 = 1.0f - firstperc;
        return new Color((int) (c1.getRed() * firstperc + c2.getRed() * p2),
                (int) (c1.getGreen() * firstperc + c2.getGreen() * p2),
                (int) (c1.getBlue() * firstperc + c2.getBlue() * p2));
    }
}

Related

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