Get fraction of hue from color - Android Graphics

Android examples for Graphics:Color Hue

Description

Get fraction of hue from color

Demo Code


//package com.java2s;
import android.graphics.Color;

public class Main {
    /**//from w ww  . j a  v a  2s.c  om
     * Get fraction of hue from color
     * @param color color
     * @return hue/360, 0..1
     */
    public static float getFractionFromColor(int color) {
        return getHueFromColor(color) / 360;
    }

    /**
     * Get hue from color
     * @param color color
     * @return color hue value, 0..360
     */
    public static float getHueFromColor(int color) {
        return getHSVFromColor(color)[0];
    }

    /**
     * Get HSV array from color
     * @param color color
     * @return HSV array, length = 3
     */
    public static float[] getHSVFromColor(int color) {
        float hsv[] = new float[3];
        Color.colorToHSV(color, hsv);
        return hsv;
    }
}

Related Tutorials