average Color - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

average Color

Demo Code


//package com.java2s;
import java.awt.*;

public class Main {
    public static Color averageColor(Color c1, Color c2, double balance) {
        return averageColor(c1, c2, balance, c1.getAlpha());
    }// w w w.jav a2s . c  om

    public static Color averageColor(Color c1, Color c2, double balance,
            int alpha) {

        int r = (int) (c1.getRed() * balance + c2.getRed()
                * (1.0 - balance));
        int g = (int) (c1.getGreen() * balance + c2.getGreen()
                * (1.0 - balance));
        int b = (int) (c1.getBlue() * balance + c2.getBlue()
                * (1.0 - balance));

        return new Color(r, g, b, alpha);
    }
}

Related Tutorials