set Saturation - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

set Saturation

Demo Code


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

public class Main {
    public static Color setSaturation(Color color, float saturation) {
        float[] hsbvals;

        if (saturation < 0.0f || saturation > 1.0f) {
            return color;
        }/*from   w  ww . jav  a 2s  .c  o m*/

        hsbvals = new float[3];
        Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(),
                hsbvals);
        hsbvals[1] = saturation;

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

        return color;
    }
}

Related Tutorials