Java Color Brighten getBrightness(Color c)

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

Description

Calculates the brightness of a color.

License

Open Source License

Parameter

Parameter Description
c The color to calculate the brightness of.

Return

A relative value of the brightness.

Declaration

public static int getBrightness(Color c) 

Method Source Code

//package com.java2s;
/*//from   ww w  . ja  v  a  2s.  c  o m
 * Copyright (c) 2009
 *
 * This file is part of HibernateJConsole.
 *
 *     HibernateJConsole is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU General Public License as published by
 *     the Free Software Foundation, either version 3 of the License, or
 *     (at your option) any later version.
 *
 *     HibernateJConsole 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 for more details.
 *
 *     You should have received a copy of the GNU General Public License
 *     along with HibernateJConsole.  If not, see <http://www.gnu.org/licenses/>.
 */

import java.awt.*;

public class Main {
    /**
     * Calculates the brightness of a color.
     * <p/>
     * Taken from: {@code http://www.nbdtech.com/blog/archive/2008/04/27/Calculating-the-Perceived-Brightness-of-a-Color.aspx}
     *
     * @param c The color to calculate the brightness of.
     * @return A relative value of the brightness.
     */
    public static int getBrightness(Color c) {
        double b = c.getRed() * c.getRed() * .241D + c.getGreen() * c.getGreen() * .691D
                + c.getBlue() * c.getBlue() * .068D;
        return (int) Math.sqrt(b);
    }
}

Related

  1. brightnessToAlpha(Image image, float alpha)
  2. changeBrightness(Color c, int percent)
  3. changeColorBrightness(final Color color, final double delta)
  4. deriveByBrightness(Color original, Color brightnessSource)
  5. deriveColorHSB(Color base, float hue, float saturation, float brightness)
  6. getBrightness(Color c)
  7. getBrightness(Color c)
  8. getBrightness(Color color)
  9. getBrightness(Color color)