| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using System;
- using System.Drawing;
- namespace shjxCamera
- {
- public class ColorPoint : IComparable<ColorPoint>
- {
- 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;
- }
- }
- }
|