Java Color Lighten lighter(Color c)

Here you can find the source of lighter(Color c)

Description

Create a color derived from the given color, but lighter.

License

Open Source License

Parameter

Parameter Description
c The color to lighten.

Return

The derived color.

Declaration

public static Color lighter(Color c) 

Method Source Code

//package com.java2s;
/*// www .  j ava  2  s.  c  o m
 * $Id$
 *
 * Copyright 1996-2008 Sun Microsystems, Inc.  All Rights Reserved.
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * This code is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License version 2 only, as
 * published by the Free Software Foundation.  Sun designates this
 * particular file as subject to the "Classpath" exception as provided
 * by Sun in the LICENSE file that accompanied this code.
 *
 * This code is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 * version 2 for more details (a copy is included in the LICENSE file that
 * accompanied this code).
 *
 * You should have received a copy of the GNU General Public License version
 * 2 along with this work; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
 * CA 95054 USA or visit www.sun.com if you need additional information or
 * have any questions.
 */

import java.awt.Color;

public class Main {
    /**
     * Create a color derived from the given color, but lighter.
     * This is currently done by decreasing it's saturation and brightness.
     * @param c The color to lighten.
     * @return The derived color.
     */
    public static Color lighter(Color c) {
        float[] hsb = Color.RGBtoHSB(c.getRed(), c.getGreen(), c.getBlue(),
                null);
        hsb[1] = hsb[1] * 0.75f; // reduce saturation by 25%
        hsb[2] = Math.min(hsb[2] * 1.1f, 1.0f); // increase brightness by 10%
        return new Color(Color.HSBtoRGB(hsb[0], hsb[1], hsb[2]));
    }
}

Related

  1. lighten(final Color color, final int amount)
  2. lighten(int r, int g, int b, double percent)
  3. lightenColor(Color col, float factor)
  4. lightenColor(Color color)
  5. lighter(Color c)
  6. lighter(Color c, boolean transparant)
  7. lighter(Color c, float factor)
  8. lighter(Color clr)
  9. lighter(Color clr, double saturationFraction)