using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RichCreator.Utility.Structs { /// /// HSV Float型颜色数组项 /// public class ZTHsvFloatColorArrayItem : ColorArrayItem { public ZTHsvFloatColorArrayItem(float hOffset,float sOffset,float vOffset,ZTPoint offset, ZTColor color):base(offset,color) { float h = 0, s = 0, v = 0; ColorUtils.RGBtoHSV(color.Red, color.Green, color.Blue, out h, out s, out v); MinHsv = new ZTHsvFloatColor(Math.Max(0,h - hOffset), Math.Max(0,s - sOffset), Math.Max(0,v - vOffset)); MaxHsv= new ZTHsvFloatColor(Math.Min(1, h + hOffset), Math.Min(1, s + sOffset), Math.Min(1, v + vOffset)); } public ZTHsvFloatColor MinHsv { get; private set; } public ZTHsvFloatColor MaxHsv { get; private set; } public override bool Compare(byte r, byte g, byte b) { float h = 0, s = 0, v = 0; ColorUtils.RGBtoHSV(r, g, b, out h, out s, out v); if (h >= MinHsv.H && h <= MaxHsv.H && s >= MinHsv.S && s <= MaxHsv.S && v >= MinHsv.V && v <= MaxHsv.V) { return true; } return false; } } }