Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void FloodFill(PixelManipulator manipulator, Point position, Pixel targetColor, Pixel replaceColor, byte threshold)
- {
- unchecked
- {
- Queue<Point> q = new Queue<Point>((manipulator.Width * manipulator.Height));
- manipulator.Position = position;
- if (!manipulator.Current.Similar(targetColor, threshold))
- return;
- q.Enqueue(manipulator.Position);
- while (q.Count > 0)
- {
- Point n = q.Dequeue();
- if (n.X < 0 || n.Y < 0 || n.X > manipulator.Width || n.Y > manipulator.Height)
- {
- continue;
- }
- manipulator.Position = n;
- if (manipulator.Current == replaceColor || !manipulator.Current.Similar(targetColor, threshold))
- {
- continue;
- }
- manipulator.Current = replaceColor;
- q.Enqueue(new Point(n.X - 1, n.Y)); //Left
- q.Enqueue(new Point(n.X + 1, n.Y)); //Right
- q.Enqueue(new Point(n.X, n.Y-1)); //Top
- q.Enqueue(new Point(n.X, n.Y+1)); //Bottom
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement