Java Color Brighten deriveByBrightness(Color original, Color brightnessSource)

Here you can find the source of deriveByBrightness(Color original, Color brightnessSource)

Description

Derives a color based on the original color and a brightness source.

License

Open Source License

Parameter

Parameter Description
original Original color.
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.

Declaration

public static Color deriveByBrightness(Color original,
        Color brightnessSource) 

Method Source Code

//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));

    }
}

Related

  1. brightness(Color c, float scale)
  2. brightness(java.awt.Color c)
  3. brightnessToAlpha(Image image, float alpha)
  4. changeBrightness(Color c, int percent)
  5. changeColorBrightness(final Color color, final double delta)
  6. deriveColorHSB(Color base, float hue, float saturation, float brightness)
  7. getBrightness(Color c)
  8. getBrightness(Color c)
  9. getBrightness(Color c)