Java Color Brighten getBrightness(Color color)

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

Description

Uses the method described at http://alienryderflex.com/hsp.html to get the <u>perceived</u> brightness of a color.

License

Open Source License

Parameter

Parameter Description
color the color

Return

int brightness on the scale of 0 to 255

Declaration

public static final int getBrightness(Color color) 

Method Source Code


//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;
    }
}

Related

  1. getBrightness(Color c)
  2. getBrightness(Color c)
  3. getBrightness(Color c)
  4. getBrightness(Color color)
  5. getBrightness(Color color)
  6. getBrightness(int red, int green, int blue)
  7. getBrightness(java.awt.Color color)
  8. getGradientBrightColors(Color baseColor, float step, float max)
  9. getRandomBrightColor()