Here you can find the source of darker(Color color, double fraction)
Parameter | Description |
---|---|
color | Color to make darker. |
fraction | Darkness fraction. |
public static Color darker(Color color, double fraction)
//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; } }