set Color Brightness - Java 2D Graphics

Java examples for 2D Graphics:Color Light

Description

set Color Brightness

Demo Code


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

public class Main {
    public static Color setBrightness(Color color, float brightness) {
        float[] hsbvals;

        hsbvals = new float[3];
        Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(),
                hsbvals);//from   www . ja v  a  2s.c om
        hsbvals[2] = brightness;
        hsbvals[2] = Math.min(hsbvals[2], 1.0f);
        hsbvals[2] = Math.max(hsbvals[2], 0.0f);

        color = new Color(
                Color.HSBtoRGB(hsbvals[0], hsbvals[1], hsbvals[2]));

        return color;
    }
}

Related Tutorials