Java examples for 2D Graphics:Color RGB
Derives a color from another color by linearly shifting its blue, green, and blue values.
/*// w w w. ja va 2 s .c o m * 09/08/2005 * * UIUtil.java - Utility methods for org.fife.ui classes. * Copyright (C) 2005 Robert Futrell * http://fifesoft.com/rtext * Licensed under a modified BSD license. * See the included license file for details. */ //package com.java2s; import java.awt.Color; public class Main { /** * Derives a color from another color by linearly shifting its blue, green, * and blue values. * * @param orig The original color. * @param darker The amount by which to decrease its r, g, and b values. * Note that you can use negative values for making a color * component "brighter." If this makes any of the three values * less than zero, zero is used for that component value; similarly, * if it makes any value greater than 255, 255 is used for that * component's value. */ public static final Color deriveColor(Color orig, int darker) { int red = orig.getRed() - darker; int green = orig.getGreen() - darker; int blue = orig.getBlue() - darker; if (red < 0) red = 0; else if (red > 255) red = 255; if (green < 0) green = 0; else if (green > 255) green = 255; if (blue < 0) blue = 0; else if (blue > 255) blue = 255; return new Color(red, green, blue); } }