by
226 10
1
5
3,622
3
Top 1% !
Famous
Tagged
Specified
OpenSource
Popularity: 3379th place

Published on:

InputName0hue
InputName1saturation
InputName2value
InputName3alpha
InputType0float
InputType1float
InputType2float
InputType3float
Languagecsharp
LicenseMIT_X11
MethodNameHSVtoRGB
OutputTypeColor

Convert from HSV to ARGB .Net Color

Copy Embed Code
<iframe id="embedFrame" style="width:600px; height:300px;"
src="https://www.snip2code.com/Embed/111962/Convert-from-HSV-to-ARGB--Net-Color?startLine=0"></iframe>
Click on the embed code to copy it into your clipboard Width Height
Leave empty to retrieve all the content Start End
//Converst from HSV values to a .net Color public static Color HSVtoRGB(float hue, float saturation, float value, float alpha) { while (hue > 1f) { hue -= 1f; } while (hue < 0f) { hue += 1f; } while (saturation > 1f) { saturation -= 1f; } while (saturation < 0f) { saturation += 1f; } while (value > 1f) { value -= 1f; } while (value < 0f) { value += 1f; } if (hue > 0.999f) { hue = 0.999f; } if (hue < 0.001f) { hue = 0.001f; } if (saturation > 0.999f) { saturation = 0.999f; } if (saturation < 0.001f) { return Color.FromArgb((int)(value * 255f), (int)(value * 255f), (int)(value * 255f)); } if (value > 0.999f) { value = 0.999f; } if (value < 0.001f) { value = 0.001f; } float h6 = hue * 6f; if (h6 == 6f) { h6 = 0f; } int ihue = (int)(h6); float p = value * (1f - saturation); float q = value * (1f - (saturation * (h6 - (float)ihue))); float t = value * (1f - (saturation * (1f - (h6 - (float)ihue)))); switch (ihue) { case 0: return Color.FromArgb((int)(alpha * 255), (int)(value * 255), (int)(t * 255), (int)(p * 255)); case 1: return Color.FromArgb((int)(alpha * 255), (int)(q * 255), (int)(value * 255), (int)(p * 255)); case 2: return Color.FromArgb((int)(alpha * 255), (int)(p * 255), (int)(value * 255), (int)(t * 255)); case 3: return Color.FromArgb((int)(alpha * 255), (int)(p * 255), (int)(q * 255), (int)(value * 255)); case 4: return Color.FromArgb((int)(alpha * 255), (int)(t * 255), (int)(p * 255), (int)(value * 255)); default: return Color.FromArgb((int)(alpha * 255), (int)(value * 255), (int)(p * 255), (int)(q * 255)); } }
If you want to be updated about similar snippets, Sign in and follow our Channels

blog comments powered by Disqus