Android examples for Graphics:Color Blend
Blend two colors
/******************************************************************************* * Copyright (c) 2011 MadRobot.// w w w . ja v a 2 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 { /** * Blend two colors * * @param color1 * @param color2 * @param f * percentage * @return Blended color */ public static int blend(int color1, int color2, float f) { return mix(color1 >>> 24, color2 >>> 24, f) << 24 | mix((color1 >> 16) & 0xff, (color2 >> 16) & 0xff, f) << 16 | mix((color1 >> 8) & 0xff, (color2 >> 8) & 0xff, f) << 8 | mix(color1 & 0xff, color2 & 0xff, f); } private static int mix(int a, int b, float f) { return (int) (a + (b - a) * f); } }