private void determineColor(Point p) { HsvColor hsv = new HsvColor(360 - m_ColorSlider.Value, 1, 1); hsv.S = p.X; hsv.V = 1 - p.Y; m_color = ColorUtilities.ConvertHsvToRgb(hsv.H, hsv.S, hsv.V); shouldFindPoint = false; m_color.ScA = (float)GetValue(ScAProperty); SetValue(HexadecimalStringProperty, m_color.ToString()); shouldFindPoint = true; }
// Converts an RGB color to an HSV color. public static HsvColor ConvertRgbToHsv(int r, int b, int g) { double delta, min; double h = 0, s, v; min = Math.Min(Math.Min(r, g), b); v = Math.Max(Math.Max(r, g), b); delta = v - min; if (v == 0.0) { s = 0; } else s = delta / v; if (s == 0) h = 0.0; else { if (r == v) h = (g - b) / delta; else if (g == v) h = 2 + (b - r) / delta; else if (b == v) h = 4 + (r - g) / delta; h *= 60; if (h < 0.0) h = h + 360; } HsvColor hsvColor = new HsvColor(); hsvColor.H = h; hsvColor.S = s; hsvColor.V = v / 255; return hsvColor; }