Пример #1
0
        public static List <Color> GetColors(LockBitmap lockb, PointGroup pg)
        {
            List <Color> colors = new List <Color>();

            if (!lockb.Locked)
            {
                throw new InvalidOperationException("Bits must be locked to get colors.");
            }

            foreach (var point in pg.Points)
            {
                if (point.X < 0 || point.X >= lockb.Width)
                {
                    throw new InvalidOperationException($"Invalid point x {point.X} must be between 0 and {lockb.Width}");
                }
                else if (point.Y < 0 || point.Y >= lockb.Width)
                {
                    throw new InvalidOperationException($"Invalid point x {point.Y} must be between 0 and {lockb.Height}");
                }

                Color col = lockb.GetPixel(point.X, point.Y);
                colors.Add(col);
            }

            return(colors);
        }
Пример #2
0
        public PointGroup OffsetCopy(int x, int y)
        {
            PointGroup points = new PointGroup();

            foreach (var point in _points)
            {
                Point newPoint = new Point(point.X + x, point.Y + y);
                points.AddPoint(newPoint);
            }

            return(points);
        }
Пример #3
0
        public static int ColorDiffWithColor(PointGroup group, Color color)
        {
            if (group == null || group.Points.Count < 2)
            {
                return(0);
            }

            double diff = 0;

            for (int i = 1; i < group.Points.Count; i++)
            {
                Point p1 = group.Points[i];
                Point p2 = group.Points[i - 1];
                diff += ColorDiff(p1, p2);
            }

            return((int)Math.Round(diff / group.Points.Count));
        }
Пример #4
0
        public bool SameColor(PointGroup points, int tolerance = 5)
        {
            if (points == null || points.Count == 0)
            {
                return(false);
            }

            int           length = Math.Min(points.Count, this.Count);
            List <double> diffs  = new List <double>();

            for (int i = 0; i < length; ++i)
            {
                Point p1   = _points[i];
                Point p2   = points[i];
                int   diff = ColorUtils.ColorDiff(p1, p2);
                diffs.Add(diff);
            }
            double avg = 0;

            diffs.ForEach((diff) => { avg += diff; });
            avg = avg / diffs.Count;
            return(avg <= tolerance);
        }
Пример #5
0
 public static bool IsSimilarColor(PointGroup group, int tolerance = DEFAULT_COLOR_TOLERANCE)
 {
     return(ColorDiff(group) <= tolerance);
 }
Пример #6
0
 public static int ColorDiff(PointGroup group)
 {
     return(ColorDiffWithColor(group, Color.Empty));
 }