Java Color Merge mergeCols(Color col1, Color col2)

Here you can find the source of mergeCols(Color col1, Color col2)

Description

Merges two Color instances, to return a new Color with averaged values for red, green & blue.

License

Open Source License

Declaration

public static Color mergeCols(Color col1, Color col2) 

Method Source Code


//package com.java2s;
/*//from   w  ww.j av  a 2 s  . co  m
 * BioAssay Ontology Annotator Tools
 * 
 * (c) 2014-2016 Collaborative Drug Discovery Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License 2.0
 * as published by the Free Software Foundation:
 * 
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 */

import java.awt.Color;

public class Main {
    /**
     * Merges two Color instances, to return a new Color with averaged values for red, green & blue.
     */
    public static Color mergeCols(Color col1, Color col2) {
        int r = col1.getRed() + col2.getRed(), g = col1.getGreen() + col2.getGreen(),
                b = col1.getBlue() + col2.getBlue();
        return new Color(r / 2, g / 2, b / 2);
    }
}

Related

  1. mergeColor(Color a, Color b)
  2. mergeColor(Color c1, Color c2)
  3. mergeColors(Color a, float fa, Color b, float fb)
  4. mergeColors(Color color1, Color color2)