Here you can find the source of brightenColor(Color color, double factor)
Parameter | Description |
---|---|
color | color to brighten |
factor | luminosity factor; if negative, the color is darkened |
public static Color brightenColor(Color color, double factor)
//package com.java2s; import java.awt.Color; public class Main { /**/*from ww w .j a va 2s . com*/ * Brightens each of the RGB components of color by the specified factor. * Note: This is identical to the java.awt.Color.brighten() method, using a variable factor. * * @param color color to brighten * @param factor luminosity factor; if negative, the color is darkened * @return brightened color */ public static Color brightenColor(Color color, double factor) { int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); int i = (int) (1.0 / (1.0 - factor)); if (r == 0 && g == 0 && b == 0) { return new Color(i, i, i); } if (r > 0 && r < i) { r = i; } if (g > 0 && g < i) { g = i; } if (b > 0 && b < i) { b = i; } return new Color(Math.min((int) (r / factor), 255), Math.min((int) (g / factor), 255), Math.min((int) (b / factor), 255)); } }