Here you can find the source of brighten(final Color color, final double percentage)
Parameter | Description |
---|---|
color | The color to brighten. |
percentage | How much brighter the new color must be. The value must be between [0.01 and 1.00] inclusive. Example: a value of 0.50 means a new color 50% brighter than the original color, so, if the original color is RGB(150, 70, 60), the new one will be RGB(255, 140, 120). Be aware that if the brighten rate surpasses a channel max value (= 255) this channel will bew cut down to this max, changing this way the color gama (deforming the color). |
public static Color brighten(final Color color, final double percentage)
//package com.java2s; /*// www. j ava 2 s.c o m * Copyright (C) 2013 Marcius da Silva da Fonseca. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library 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 library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301 USA */ import java.awt.Color; public class Main { /** * Returns a new color that is <tt>percentage</tt> brighter than the original. * <p/> * The original color is not modified in the process. * * @param color The color to brighten. * @param percentage How much brighter the new color must be. * The value must be between [0.01 and 1.00] inclusive. * Example: a value of 0.50 means a new color 50% brighter than the original color, so, * if the original color is RGB(150, 70, 60), the new one will be RGB(255, 140, 120). * Be aware that if the brighten rate surpasses a channel max value (= 255) this channel * will bew cut down to this max, changing this way the color gama (deforming the color). * @return The new, brighten color. */ public static Color brighten(final Color color, final double percentage) { if (percentage < 0.01 || percentage > 1.00) { throw new IllegalArgumentException("Percentage must be between [0.01 - 1.00]"); } int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); r = Math.min((int) (r * (1.00 + percentage)), 255); g = Math.min((int) (g * (1.00 + percentage)), 255); b = Math.min((int) (b * (1.00 + percentage)), 255); return new Color(r, g, b, color.getAlpha()); } }