Here you can find the source of deriveByBrightness(Color original, Color brightnessSource)
Parameter | Description |
---|---|
original | Original color. |
brightnessSource | Brightness source. |
public static Color deriveByBrightness(Color original, Color brightnessSource)
//package com.java2s; import java.awt.Color; public class Main { /**/*from w ww .ja v a 2 s. c om*/ * Derives a color based on the original color and a brightness source. The * resulting color has the same hue and saturation as the original color, * but its brightness is shifted towards the brightness of the brightness * source. Thus, a light red color shifted towards dark green will become * dark red. * * @param original * Original color. * @param brightnessSource * Brightness source. * @return Derived color that has the same hue and saturation as the * original color, but its brightness is shifted towards the * brightness of the brightness source. */ public static Color deriveByBrightness(Color original, Color brightnessSource) { float[] hsbvalsOrig = new float[3]; Color.RGBtoHSB(original.getRed(), original.getGreen(), original.getBlue(), hsbvalsOrig); float[] hsbvalsBrightnessSrc = new float[3]; Color.RGBtoHSB(brightnessSource.getRed(), brightnessSource.getGreen(), brightnessSource.getBlue(), hsbvalsBrightnessSrc); return new Color(Color.HSBtoRGB(hsbvalsOrig[0], hsbvalsOrig[1], (hsbvalsBrightnessSrc[2] + hsbvalsOrig[2]) / 2.0f)); } }