Java Color Lighten lighter(Color color, double fraction)

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

Description

Make a color lighter.

License

LGPL

Parameter

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

Return

Lighter color.

Declaration

public static Color lighter(Color color, double fraction) 

Method Source Code


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

import java.awt.Color;

public class Main {
    /**/*from   ww w .jav a  2  s  . c  o m*/
     * Make a color lighter.
     * @param color     Color to make lighter.
     * @param fraction  Darkness fraction.
     * @return          Lighter color.
     */
    public static Color lighter(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. lighter(Color c)
  2. lighter(Color c, boolean transparant)
  3. lighter(Color c, float factor)
  4. lighter(Color clr)
  5. lighter(Color clr, double saturationFraction)
  6. lighter(Color color, float ratio)
  7. lighter(final Color color, final int rgbOffset)
  8. lighter(final Color color, float factor)
  9. lighterColor(Color c, double amount)