Java Color Darker getDarkerColor(Color color)

Here you can find the source of getDarkerColor(Color color)

Description

get Darker Color

License

Open Source License

Parameter

Parameter Description
color The color to make darker

Return

The darker color

Declaration

public static Color getDarkerColor(Color color) 

Method Source Code


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

public class Main {
    private static final double DARKER_SCALE = 0.95;
    private static final int MINVALUE = 0;
    private static final int MAXVALUE = 255;

    /**//w w  w . java  2s  .c o m
     * 
     * @param color The color to make darker
     * @return The darker color
     */
    public static Color getDarkerColor(Color color) {
        return getScaledColor(color, DARKER_SCALE);
    }

    /**
     * 
     * @param color The color to adjust
     * @param scaleFactor the amount to scale the colors by
     * @return The adjusted color
     */
    public static Color getScaledColor(Color color, double scaleFactor) {
        return new Color(getScaledColorComponent(color.getRed(), scaleFactor),
                getScaledColorComponent(color.getGreen(), scaleFactor),
                getScaledColorComponent(color.getBlue(), scaleFactor));
    }

    private static int getScaledColorComponent(int colorComponent, double scaleFactor) {
        int scaledValue = (int) (colorComponent * scaleFactor);
        if (scaledValue < MINVALUE) {
            scaledValue = MINVALUE;
        } else if (scaledValue > MAXVALUE) {
            scaledValue = MAXVALUE;
        }
        return scaledValue;
    }
}

Related

  1. getDarkColor()
  2. getDarkColors(Color[] colors, double fraction)
  3. getDarker(Color c)
  4. getDarker(Color color)
  5. getDarker(Color color, double factor)
  6. getDarkerColor(Color color, double diff)
  7. getDarkerLine(Color c, float alternateRowDarkerFactor)
  8. getLineDarkColor()
  9. initializePattern(Color light, Color dark)