Here you can find the source of rgb2hsv(int r, int g, int b)
public static float[] rgb2hsv(int r, int g, int b)
//package com.java2s; //License from project: Open Source License public class Main { public static float[] rgb2hsv(int r, int g, int b) { float r1 = ((float) r) / 255; float g1 = ((float) g) / 255; float b1 = ((float) b) / 255; float cMax = max(r1, g1, b1); float cMin = min(r1, g1, b1); float delta = cMax - cMin; float h = 0, s = 0, v = 0; if (delta == 0) { h = 0;//from w w w. j a v a 2 s. c o m } else if (cMax == r1) { h = 60 * (((g1 - b1) / delta) % 6); } else if (cMax == g1) { h = 60 * (((b1 - r1) / delta) + 2); } else if (cMax == b1) { h = 60 * (((r1 - g1) / delta) + 4); } if (h < 0) h += 360; if (cMax == 0) { s = 0; } else { s = delta / cMax; } v = cMax; return new float[] { h, s, v }; } private static float max(float... f) { float max = Float.MIN_VALUE; for (float n : f) { if (max < n) max = n; } return max; } private static float min(float... f) { float min = Float.MAX_VALUE; for (float n : f) { if (min > n) min = n; } return min; } }