Returns a color whose brightness has been scaled by the provided factor. - Java 2D Graphics

Java examples for 2D Graphics:Color Light

Description

Returns a color whose brightness has been scaled by the provided factor.

Demo Code


//package com.java2s;
import java.awt.*;

public class Main {
    /**//w  w  w .  j av  a2 s  .  co m
     * Returns a color whose brightness has been scaled by the provided factor.
     * @param color The input color.
     * @param factor The scale factor.
     * @return The rescaled color.
     */
    public static Color getRescaledColor(Color color, float factor) {
        float hsbVals[] = Color.RGBtoHSB(color.getRed(), color.getGreen(),
                color.getBlue(), null);
        return Color.getHSBColor(hsbVals[0], hsbVals[1], factor
                * hsbVals[2]);
    }
}

Related Tutorials