Java Color Darker darker(Color color, double fraction)

Here you can find the source of darker(Color color, double fraction)

Description

Make a color darker.

License

LGPL

Parameter

Parameter Description
color Color to make darker.
fraction Darkness fraction.

Return

Darker color.

Declaration

public static Color darker(Color color, double fraction) 

Method Source Code


//package com.java2s;
// licensed under GNU LGPL

import java.awt.Color;

public class Main {
    /**/*from   w  w  w  .j  a  v  a2  s .  co  m*/
     * Make a color darker.
     * @param color     Color to make darker.
     * @param fraction  Darkness fraction.
     * @return          Darker color.
     */
    public static Color darker(Color color, double fraction) {
        int red = (int) Math.round(color.getRed() * (1.0 - fraction));
        int green = (int) Math.round(color.getGreen() * (1.0 - fraction));
        int blue = (int) Math.round(color.getBlue() * (1.0 - fraction));
        return new Color(normalize(red), normalize(green), normalize(blue), color.getAlpha());
    }

    private static int normalize(int comp) {
        if (comp < 0)
            return 0;
        else if (comp > 255)
            return 255;
        else
            return comp;
    }
}

Related

  1. darker(Color c, float factor)
  2. darker(Color col, double FACTOR)
  3. darker(Color color)
  4. darker(Color color)
  5. darker(Color color, double factor)
  6. darker(Color color, float fraction)
  7. darker(Color color, float ratio)
  8. darker(final Color color, final int rgbOffset)
  9. darker(final Color color, float factor)