Java tutorial
//package com.java2s; /* * Copyright 2015 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import android.graphics.Color; public class Main { /** * Blend between two ARGB colors using the given ratio. * * <p>A blend ratio of 0.0 will result in {@code color1}, 0.5 will give an even blend, * 1.0 will result in {@code color2}.</p> * * @param color1 the first ARGB color * @param color2 the second ARGB color * @param ratio the blend ratio of {@code color1} to {@code color2} */ public static int blendARGB(int color1, int color2, float ratio) { final float inverseRatio = 1 - ratio; float a = Color.alpha(color1) * inverseRatio + Color.alpha(color2) * ratio; float r = Color.red(color1) * inverseRatio + Color.red(color2) * ratio; float g = Color.green(color1) * inverseRatio + Color.green(color2) * ratio; float b = Color.blue(color1) * inverseRatio + Color.blue(color2) * ratio; return Color.argb((int) a, (int) r, (int) g, (int) b); } }