Here you can find the source of hsvToRgb(int hue, int saturation, int value)
Parameter | Description |
---|---|
hue | - A positive integer, which, modulo 360, will represent the hue of the color |
saturation | - An integer between 0 and 100 |
value | - An integer between 0 and 100 |
public static int hsvToRgb(int hue, int saturation, int value)
//package com.java2s; //License from project: Apache License public class Main { /**//from w ww .j a v a2s.co m * Converts the hue, saturation and value color model to the red, green and * blue color model * * @param hue * - A positive integer, which, modulo 360, will represent the * hue of the color * @param saturation * - An integer between 0 and 100 * @param value * - An integer between 0 and 100 * @return */ public static int hsvToRgb(int hue, int saturation, int value) { // Source: en.wikipedia.org/wiki/HSL_and_HSV#Converting_to_RGB#From_HSV hue %= 360; float s = (float) saturation / 100; float v = (float) value / 100; float c = v * s; float h = (float) hue / 60; float x = c * (1 - Math.abs(h % 2 - 1)); float r, g, b; switch (hue / 60) { case 0: r = c; g = x; b = 0; break; case 1: r = x; g = c; b = 0; break; case 2: r = 0; g = c; b = x; break; case 3: r = 0; g = x; b = c; break; case 4: r = x; g = 0; b = c; break; case 5: r = c; g = 0; b = x; break; default: return 0; } float m = v - c; return ((int) ((r + m) * 255) << 16) | ((int) ((g + m) * 255) << 8) | ((int) ((b + m) * 255)); } }