Finds the closest hue possible to given color. - Java 2D Graphics

Java examples for 2D Graphics:Color

Description

Finds the closest hue possible to given color.

Demo Code

/** Copyright 2012, Adam L. Davis, all rights reserved. */
//package com.java2s;
import java.awt.Color;

public class Main {
    /**//from   w  ww.  j  av a2 s. c om
     * Finds the closest hue possible to given color.
     * 
     * @param color
     *            The color to match.
     * @return Hue float value between 0 and 1.
     */
    public static float findHue(Color color) {
        float[] hsbvals = new float[3];
        Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(),
                hsbvals);
        return hsbvals[0];
    }
}

Related Tutorials