Here you can find the source of getBrightness(Color c)
Parameter | Description |
---|---|
c | The color to calculate the brightness of. |
public static int getBrightness(Color c)
//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); } }