Color between two colors - Android Graphics

Android examples for Graphics:Color

Description

Color between two colors

Demo Code

/*******************************************************************************
 * Copyright (c) 2011 MadRobot.//from  w ww .j  a v  a2  s . c  o  m
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Contributors:
 *  Elton Kent - initial API and implementation
 ******************************************************************************/
//package com.java2s;

public class Main {
    /**
     * Color between two colors
     * 
     * @param color1
     *            argb value of first color
     * @param color2
     *            argb value of second color
     * @param prop
     * @param max
     * @return Middle color
     */
    public static final int middleColor(int color1, int color2, int prop,
            int max) {
        int red = (((color1 >> 16) & 0xff) * prop + ((color2 >> 16) & 0xff)
                * (max - prop))
                / max;
        int green = (((color1 >> 8) & 0xff) * prop + ((color2 >> 8) & 0xff)
                * (max - prop))
                / max;
        int blue = (((color1 >> 0) & 0xff) * prop + ((color2 >> 0) & 0xff)
                * (max - prop))
                / max;
        int color = red << 16 | green << 8 | blue;
        return color;
    }
}

Related Tutorials