Here you can find the source of RgbToHsl(float r, float g, float b, float a)
static float[] RgbToHsl(float r, float g, float b, float a)
//package com.java2s; //License from project: Apache License public class Main { static float[] RgbToHsl(float r, float g, float b, float a) { float h = 0, s = 0, l; float max = Math.max(r, Math.max(g, b)); float min = Math.min(r, Math.min(g, b)); // hue//from www .j a va 2 s. co m if (max == min) { h = 0; // undefined } else if (max == r && g >= b) { h = 1.0f / 6.0f * (g - b) / (max - min); } else if (max == r && g < b) { h = 1.0f / 6.0f * (g - b) / (max - min) + 1.0f; } else if (max == g) { h = 1.0f / 6.0f * (b - r) / (max - min) + 1.0f / 3.0f; } else if (max == b) { h = 1.0f / 6.0f * (r - g) / (max - min) + 2.0f / 3.0f; } // luminance l = (max + min) / 2.0f; // saturation if (l == 0 || max == min) { s = 0; } else if (0 < l && l <= 0.5) { s = (max - min) / (max + min); } else if (l > 0.5) { s = (max - min) / (2 - (max + min)); //(max-min > 0)? } float[] result = new float[4]; result[0] = h; result[1] = s; result[2] = l; result[3] = a; return result; } }