Java examples for 2D Graphics:Color Dark
Returns a darker version of the given color.
/**//from w w w . j a v a2s. 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. */ //package com.java2s; 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()); } }