Here you can find the source of getBrightness(Color color)
Uses the method described at http://alienryderflex.com/hsp.html to get the <u>perceived</u> brightness of a color.
Parameter | Description |
---|---|
color | the color |
public static final int getBrightness(Color color)
//package com.java2s; import java.awt.Color; public class Main { /**//www . j av a2 s . c o m * Uses the method described at http://alienryderflex.com/hsp.html to get * the <u>perceived</u> brightness of a color. * @param color the color * @return int brightness on the scale of 0 to 255 */ public static final int getBrightness(Color color) { // original coefficients final double cr = 0.241; final double cg = 0.691; final double cb = 0.068; // another set of coefficients // final double cr = 0.299; // final double cg = 0.587; // final double cb = 0.114; double r, g, b; r = color.getRed(); g = color.getGreen(); b = color.getBlue(); // compute the weighted distance double result = Math.sqrt(cr * r * r + cg * g * g + cb * b * b); return (int) result; } }