using System; using System.Drawing; namespace shjxCamera { public class ColorPoint : IComparable { public string Tag { get; set; } public int R { get; set; } public int G { get; set; } public int B { get; set; } public int Gray { get; set; } public int Hue { get; set; } public float Saturation { get; set; } public float Brightness { get; set; } // 计算色相差 public static int HueDiff(ColorPoint cp1, ColorPoint cp2) { int a = cp1.Hue; int b = cp2.Hue; if (a >= b) { return Math.Min(a - b, b - a + 360); } else { return Math.Min(b - a, a - b + 360); } } public ColorPoint(int r, int g, int b, string tag) { Tag = tag; R = r; G = g; B = b; Gray = Math.Min(255, (int)(R * 0.299 + G * 0.587 + B * 0.114)); Color color = Color.FromArgb(R, G, B); Hue = (int)color.GetHue(); Saturation = color.GetSaturation(); Brightness = color.GetBrightness(); } public int CompareTo(ColorPoint obj) { return Hue - obj.Hue; } } }