Java Color Darker darker(Color c, double p)

Here you can find the source of darker(Color c, double p)

Description

darker

License

Open Source License

Declaration

public static Color darker(Color c, double p) 

Method Source Code


//package com.java2s;
/*// w  w  w.  j  a  v  a2  s.  c o m
 * Copyright 2005 MH-Software-Entwicklung. All rights reserved.
 * Use is subject to license terms.
 */

import java.awt.*;

public class Main {
    public static Color darker(Color c, double p) {
        if (c == null) {
            return null;
        }

        double r = c.getRed();
        double g = c.getGreen();
        double b = c.getBlue();

        r -= (r * p) / 100.0;
        g -= (g * p) / 100.0;
        b -= (b * p) / 100.0;

        return createColor((int) r, (int) g, (int) b);
    }

    public static final Color createColor(int r, int g, int b) {
        return new Color(((r & 0xFF) << 16) | ((g & 0xFF) << 8) | ((b & 0xFF) << 0));
    }
}

Related

  1. darken(final Color color, final int amount)
  2. darkenColor(Color color)
  3. darker(Color c)
  4. darker(Color c)
  5. darker(Color c, double factor)
  6. darker(Color c, double p)
  7. darker(Color c, float factor)
  8. darker(Color col, double FACTOR)
  9. darker(Color color)