CSharp examples for System.Drawing:Color HSV
Returns a Color struct based on HSV model.
// Copyright (c) Microsoft. All rights reserved. using Windows.UI; using System.Reflection; using System;/*from w w w . j av a 2 s .co m*/ public class Main{ /// <summary> /// Returns a Color struct based on HSV model. /// </summary> /// <param name="hue">0..360 range hue</param> /// <param name="saturation">0..1 range saturation</param> /// <param name="value">0..1 range value</param> /// <param name="alpha">0..1 alpha</param> /// <returns>A Color object</returns> public static Color FromHsv(double hue, double saturation, double value, double alpha = 1.0) { if (hue < 0 || hue > 360) { throw new ArgumentOutOfRangeException(nameof(hue)); } double chroma = value * saturation; double h1 = hue / 60; double x = chroma * (1 - Math.Abs((h1 % 2) - 1)); double m = value - chroma; double r1, g1, b1; if (h1 < 1) { r1 = chroma; g1 = x; b1 = 0; } else if (h1 < 2) { r1 = x; g1 = chroma; b1 = 0; } else if (h1 < 3) { r1 = 0; g1 = chroma; b1 = x; } else if (h1 < 4) { r1 = 0; g1 = x; b1 = chroma; } else if (h1 < 5) { r1 = x; g1 = 0; b1 = chroma; } else { r1 = chroma; g1 = 0; b1 = x; } byte r = (byte)(255 * (r1 + m)); byte g = (byte)(255 * (g1 + m)); byte b = (byte)(255 * (b1 + m)); byte a = (byte)(255 * alpha); return Color.FromArgb(a, r, g, b); } }