saturate Color - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

saturate Color

Demo Code

/*/*w w w . ja va 2  s. co  m*/
 * Copyright 2003-2011 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
//package com.java2s;
import java.awt.*;

public class Main {
    public static Color saturateColor(Color c, float factor) {
        float[] hsb = new float[3];
        Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(), hsb);
        float saturation = hsb[1];
        saturation = saturation * factor;
        if (saturation > 1.0f)
            saturation = 1.0f;
        hsb[1] = saturation;
        final Color result = Color.getHSBColor(hsb[0], hsb[1], hsb[2]);
        return new Color(result.getRed(), result.getGreen(),
                result.getBlue(), c.getAlpha());
    }
}

Related Tutorials