Java Color Darker darker(final Color color, final int rgbOffset)

Here you can find the source of darker(final Color color, final int rgbOffset)

Description

Returns a darker version of the given color.

License

Apache License

Parameter

Parameter Description
color Base color to use.
rgbOffset Offset by which the color should be darkened.

Return

a darker version of the given color.

Declaration

public static Color darker(final Color color, final int rgbOffset) 

Method Source Code

//package com.java2s;
/**/*from w  ww.j a va 2  s  .  c o  m*/
 * 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.
 */

import java.awt.*;

public class Main {
    /**
     * Returns a darker version of the given color.
     *
     * @param color     Base color to use.
     * @param rgbOffset Offset by which the color should be darkened.
     * @return a darker version of the given color.
     */
    public static Color darker(final Color color, final int rgbOffset) {
        if (color == null)
            throw new IllegalArgumentException("Parameter 'color' must not be null!");
        final int red = Math.max(color.getRed() - rgbOffset, 0);
        final int green = Math.max(color.getGreen() - rgbOffset, 0);
        final int blue = Math.max(color.getBlue() - rgbOffset, 0);
        return new Color(red, green, blue, color.getAlpha());
    }
}

Related

  1. darker(Color color)
  2. darker(Color color, double factor)
  3. darker(Color color, double fraction)
  4. darker(Color color, float fraction)
  5. darker(Color color, float ratio)
  6. darker(final Color color, float factor)
  7. darker(int channel, int intensity)
  8. darkerColor(Color c)
  9. darkerColor(Color c, double amount)