merge Colors - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

merge Colors

Demo Code


import java.awt.Color;
import java.util.LinkedHashMap;
import java.util.Map;
import org.apache.log4j.*;

public class Main{
    public static Color mergeColors(Color... colors) {
        int red = 0;
        int blue = 0;
        int green = 0;
        int alpha = 0;
        boolean first = true;
        for (Color c : colors) {
            red += c.getRed();/*from  ww w.  j a  v a  2  s. c  o  m*/
            blue += c.getBlue();
            green += c.getGreen();
            alpha += c.getAlpha();
        }
        return new Color(red / colors.length, green / colors.length, blue
                / colors.length, alpha / colors.length);
    }
}

Related Tutorials