Java examples for 2D Graphics:Color
Fades the color by multiplying the saturation value by 0.5 and the brightness by 1.3.
/**/*from w w w .ja v a2 s. c om*/ * Copyright 1998-2008, CHISEL Group, University of Victoria, Victoria, BC, Canada. * All rights reserved. */ //package com.java2s; import java.awt.Color; public class Main { /** * Fades the color by multiplying the saturation value by 0.5 and the brightness by 1.3. * @param color * @return Color */ public static Color fadeColor(Color color) { return fadeColor(color, 0.5f, 1.3f); } /** * Fades the color by multiplying the sFactor to the color's saturation, and * multiplying bFactor by the color's brightness. * @param color * @param sFactor the saturation factor * @param bFactor the brightness factor * @return Color */ public static Color fadeColor(Color color, float sFactor, float bFactor) { float[] hsb = new float[3]; int r = color.getRed(); int g = color.getGreen(); int b = color.getBlue(); Color.RGBtoHSB(r, g, b, hsb); // we want a colour with the same hue, slightly less saturation, and slightly more brightness hsb[1] = hsb[1] * sFactor; // doesn't work so well with colors close to grey, because no colour to saturate hsb[2] = Math.min(1.0f, hsb[2] * bFactor); // if brightness goes above 1.0 we get a different hue!? return Color.getHSBColor(hsb[0], hsb[1], hsb[2]); } }