Here you can find the source of rgbToHsv(int red, int green, int blue)
Parameter | Description |
---|---|
b | The blue color value |
public static double[] rgbToHsv(int red, int green, int blue)
//package com.java2s; //License from project: Open Source License public class Main { /**// w w w. j a va 2 s .c o m * Converts an RGB color value [0-255] to HSV [0-1]. * * @param Number r The red color value * @param Number g The green color value * @param Number b The blue color value * @return double[] The HSV representation */ public static double[] rgbToHsv(int red, int green, int blue) { double r = (double) red / 255.0; double g = (double) green / 255.0; double b = (double) blue / 255.0; double max = Math.max(Math.max(r, g), b); double min = Math.min(Math.min(r, g), b); double h = 0; double s = 0; double v = max; double d = max - min; s = max == 0 ? 0 : d / max; if (max == min) { h = 0; // achromatic } else { if (max == r) { h = (g - b) / d + (g < b ? 6 : 0); } else if (max == g) { h = (b - r) / d + 2; } else if (max == b) { h = (r - g) / d + 4; } h /= 6; } return new double[] { h, s, v }; } }