public static Color ToColor(this HsvInfo hsvInfo) { int hi = Convert.ToInt32(Math.Floor(hsvInfo.Hue / 60)) % 6; double f = hsvInfo.Hue / 60 - Math.Floor(hsvInfo.Hue / 60); hsvInfo.Value *= 255; int v = Convert.ToInt32(hsvInfo.Value); int p = Convert.ToInt32(hsvInfo.Value * (1 - hsvInfo.Saturation)); int q = Convert.ToInt32(hsvInfo.Value * (1 - f * hsvInfo.Saturation)); int t = Convert.ToInt32(hsvInfo.Value * (1 - (1 - f) * hsvInfo.Saturation)); switch (hi) { case 0: return(new Color(v, t, p)); case 1: return(new Color(q, v, p)); case 2: return(new Color(p, v, t)); case 3: return(new Color(p, q, v)); case 4: return(new Color(t, p, v)); default: return(new Color(v, p, q)); } }
public static Color AddHsv(this Color color, int hue, double saturation = 0, double value = 0) { HsvInfo hsvInfo = color.ToHsv(); hsvInfo.Hue += hue; hsvInfo.Saturation += saturation; hsvInfo.Value += value; return(hsvInfo.ToColor()); }