Java tutorial
//package com.java2s; /* * Copyright (C) 2011,2012 Southern Storm Software, Pty Ltd. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import android.graphics.Color; public class Main { /** * Lighten a color by a specific factor. * * @param color the color to lighten * @param factor the factor to apply; e.g. 150 makes the color 50% brighter, 50 * makes the color 50% darker, 100 makes no change. * * @return the lightened version of the color */ public static int lightenColor(int color, int factor) { float[] hsv = new float[3]; Color.colorToHSV(color, hsv); float s = hsv[1]; float v = hsv[2] * factor / 100.0f; if (v > 1.0f) { // Value has overflowed, so adjust the saturation instead. s -= v - 1.0f; if (s < 0) s = 0; v = 1.0f; } hsv[1] = s; hsv[2] = v; return Color.HSVToColor(hsv); } }