Java tutorial
//package com.java2s; //License from project: Apache License public class Main { /** * Returns the hue component of a color int. * * @return A value between 0.0f and 1.0f * * @hide Pending API council */ public static float hue(int color) { int r = (color >> 16) & 0xFF; int g = (color >> 8) & 0xFF; int b = color & 0xFF; int V = Math.max(b, Math.max(r, g)); int temp = Math.min(b, Math.min(r, g)); float H; if (V == temp) { H = 0; } else { final float vtemp = (float) (V - temp); final float cr = (V - r) / vtemp; final float cg = (V - g) / vtemp; final float cb = (V - b) / vtemp; if (r == V) { H = cb - cg; } else if (g == V) { H = 2 + cr - cb; } else { H = 4 + cg - cr; } H /= 6.f; if (H < 0) { H++; } } return H; } }