示例#1
0
        public void FloodArea(int x, int y, Color colorToSet, Color colorClickedOn)
        {
            Dictionary <Tuple <int, int>, bool> PosDone = new Dictionary <Tuple <int, int>, bool>();
            Queue <Pixel> PixelStack = new Queue <Pixel>();

            PixelStack.Enqueue(new Pixel()
            {
                Color = colorClickedOn, X = x, Y = y
            });

            while (PixelStack.Count > 0)
            {
                var pixel = PixelStack.Dequeue();
                x = pixel.X;
                y = pixel.Y;

                var key = new Tuple <int, int>(x, y);

                if (x < 0 || y < 0 || y > DrawingImageHeight - 1 || x > DrawingImageWidth - 1 || PosDone.ContainsKey(key))
                {
                    continue;
                }
                PosDone[key] = true;
                var color = UnlockedBitmap.GetPixel(x, y); // DrawingImage.GetPixel(x, y);

                if (color.A == 0)
                {
                    color = Color.Transparent;
                }
                if (color == colorClickedOn)
                {
                    UnlockedBitmap.SetPixel(x, y, colorToSet);
                }
                else
                {
                    continue;
                }

                PixelStack.Enqueue(new Pixel()
                {
                    Color = color, X = x - 1, Y = y
                });
                PixelStack.Enqueue(new Pixel()
                {
                    Color = color, X = x, Y = y - 1
                });

                PixelStack.Enqueue(new Pixel()
                {
                    Color = color, X = x, Y = y + 1
                });
                PixelStack.Enqueue(new Pixel()
                {
                    Color = color, X = x + 1, Y = y
                });
            }
        }
示例#2
0
        public void DrawPixel(int X, int Y, MouseButtons button, bool DelayRefresh = false)
        {
            Color foreColor = GetCurrentColor(button);

            var scale = (decimal)(Zoom / 100.0f);

            var x = (int)(X / scale);
            var y = (int)(Y / scale);

            if (x < 0)
            {
                x = 0;
            }
            if (y < 0)
            {
                y = 0;
            }

            if (x >= DrawingImageWidth)
            {
                x = DrawingImageWidth - 1;
            }
            if (y >= DrawingImageHeight)
            {
                y = DrawingImageHeight - 1;
            }

            if (ColorModeActive == ColorMode.Blend && ((OpacityPen != 0 && OpacityPen != 255) || (foreColor.A != 0 && foreColor.A != 255)))
            {
                var ColorA = (foreColor.A != 0 && foreColor.A != 255) ? foreColor : Color.FromArgb(OpacityPen, foreColor);
                var ColorB = UnlockedBitmap.GetPixel(x, y);
                if (ColorB == Color.Transparent || ColorB == NoColor)
                {
                    UnlockedBitmap.SetPixel(x, y, ColorA);
                }
                else
                {
                    UnlockedBitmap.SetPixel(x, y, Merge(x, y, ColorA, ColorB));
                }
            }
            else
            {
                if (OpacityPen != 255)
                {
                    UnlockedBitmap.SetPixel(x, y, Color.FromArgb(OpacityPen, foreColor));
                }
                else
                {
                    UnlockedBitmap.SetPixel(x, y, foreColor);
                }
            }

            if (!DelayRefresh)
            {
                fastDraw1.Refresh();
            }
        }