Returns a lighter version of the given color. - Java 2D Graphics

Java examples for 2D Graphics:Color Light

Description

Returns a lighter version of the given color.

Demo Code

/**/*from  w  w  w  .j av a 2 s  . com*/
 * This class offers a few utility methods useful when handling Colors.
 * <p/>
 * <hr/> Copyright 2006-2012 Torsten Heup
 * <p/>
 * 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
 * <p/>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p/>
 * 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 {
    /**
     * Returns a lighter version of the given color.
     *
     * @param color     Base color to use.
     * @param rgbOffset Offset by which the color should be lightened.
     * @return a lighter version of the given color.
     */
    public static Color lighter(final Color color, final int rgbOffset) {
        if (color == null)
            throw new IllegalArgumentException(
                    "Parameter 'color' must not be null!");
        final int red = Math.min(color.getRed() + rgbOffset, 255);
        final int green = Math.min(color.getGreen() + rgbOffset, 255);
        final int blue = Math.min(color.getBlue() + rgbOffset, 255);
        return new Color(red, green, blue, color.getAlpha());
    }
}

Related Tutorials