Here you can find the source of RGBToHSV(float... rgb)
public static float[] RGBToHSV(float... rgb)
//package com.java2s; // it under the terms of the GNU General Public License as published by public class Main { public static float[] RGBToHSV(float... rgb) { float r = Math.min(Math.max(rgb[0], 0f), 1f); float g = Math.min(Math.max(rgb[1], 0f), 1f); float b = Math.min(Math.max(rgb[2], 0f), 1f); float min = Math.min(r, Math.min(g, b)); float max = Math.max(r, Math.max(g, b)); float delta = max - min; if (max == 0f) return new float[] { 0f, 0f, 0f }; float s = delta / max; float h = 0f; if (delta == 0f) h = 0f;//from ww w . j a v a 2 s. com else if (rgb[0] == max) h = (rgb[1] - rgb[2]) / delta; else if (rgb[1] == max) h = 2 + (rgb[2] - rgb[0]) / delta; else h = 4 + (rgb[0] - rgb[1]) / delta; h *= 60; if (h < 0) h += 360; return new float[] { h / 360f, s, max }; } }