Java Color Darker darken(final Color color, final int amount)

Here you can find the source of darken(final Color color, final int amount)

Description

Darkens of the desired amount the given color.

License

Open Source License

Parameter

Parameter Description
color Color to darken.
amount Amont to darken the color of.

Return

The darkened color.

Declaration

private static Color darken(final Color color, final int amount) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.awt.Color;

public class Main {
    /**/* w  w w .j  av a 2  s.c o  m*/
     * Darkens of the desired amount the given color.
     * @param color
     *            Color to darken.
     * @param amount
     *            Amont to darken the color of.
     * @return The darkened color.
     */
    private static Color darken(final Color color, final int amount) {
        int red = (color.getRed() - amount < 0) ? 0 : color.getRed() - amount;
        int green = (color.getGreen() - amount < 0) ? 0 : color.getGreen() - amount;
        int blue = (color.getBlue() - amount < 0) ? 0 : color.getBlue() - amount;
        Color colorLightened = new Color(red, green, blue);
        return colorLightened;
    }
}

Related

  1. darken(Color c, double f)
  2. darken(Color col)
  3. darken(final Color color, final double percentage)
  4. darkenColor(Color color)
  5. darker(Color c)
  6. darker(Color c)
  7. darker(Color c, double factor)