コード例 #1
0
ファイル: Canvas.cs プロジェクト: AlexAksentyev/tsvme
        private void InkArea(MouseEventArgs e)
        {
            InkPoint[] arr = new InkPoint[1000];
            InkPoint[] newarr = new InkPoint[1000];
            int length = 1;
            int newlength = 1;
            pixelColor = Color.Empty;

            arr[0].x = e.X;
            arr[0].y = e.Y;

            bmp.SetPixel(arr[0].x, arr[0].y, mf.inkColor);

            while (newlength != 0)
            {
                newlength = 0;
                for (int i = 0; i < length; i++)
                {
                    if (arr[i].x < bmp.Width-1)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x + 1, arr[i].y);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x + 1, arr[i].y, mf.inkColor);
                            newarr[newlength].x = arr[i].x + 1;
                            newarr[newlength].y = arr[i].y;
                            newlength++;
                        }
                    }

                    if (arr[i].x > 0)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x - 1, arr[i].y);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x - 1, arr[i].y, mf.inkColor);
                            newarr[newlength].x = arr[i].x - 1;
                            newarr[newlength].y = arr[i].y;
                            newlength++;
                        }
                    }

                    if (arr[i].y < bmp.Height-1)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x, arr[i].y+1);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x, arr[i].y + 1, mf.inkColor);
                            newarr[newlength].x = arr[i].x;
                            newarr[newlength].y = arr[i].y + 1;
                            newlength++;
                        }
                    }

                    if (arr[i].y > 0)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x, arr[i].y - 1);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x, arr[i].y - 1, mf.inkColor);
                            newarr[newlength].x = arr[i].x;
                            newarr[newlength].y = arr[i].y - 1;
                            newlength++;
                        }
                    }
                }
                for (int i = 0; i < newlength; i++)
                {
                    arr[i].x = newarr[i].x;
                    arr[i].y = newarr[i].y;
                }
                length = newlength;

            }
        }
コード例 #2
0
        private void InkArea(MouseEventArgs e)
        {
            InkPoint[] arr       = new InkPoint[1000];
            InkPoint[] newarr    = new InkPoint[1000];
            int        length    = 1;
            int        newlength = 1;

            pixelColor = Color.Empty;

            arr[0].x = e.X;
            arr[0].y = e.Y;

            bmp.SetPixel(arr[0].x, arr[0].y, mf.inkColor);

            while (newlength != 0)
            {
                newlength = 0;
                for (int i = 0; i < length; i++)
                {
                    if (arr[i].x < bmp.Width - 1)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x + 1, arr[i].y);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x + 1, arr[i].y, mf.inkColor);
                            newarr[newlength].x = arr[i].x + 1;
                            newarr[newlength].y = arr[i].y;
                            newlength++;
                        }
                    }

                    if (arr[i].x > 0)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x - 1, arr[i].y);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x - 1, arr[i].y, mf.inkColor);
                            newarr[newlength].x = arr[i].x - 1;
                            newarr[newlength].y = arr[i].y;
                            newlength++;
                        }
                    }

                    if (arr[i].y < bmp.Height - 1)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x, arr[i].y + 1);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x, arr[i].y + 1, mf.inkColor);
                            newarr[newlength].x = arr[i].x;
                            newarr[newlength].y = arr[i].y + 1;
                            newlength++;
                        }
                    }

                    if (arr[i].y > 0)
                    {
                        pixelColor = bmp.GetPixel(arr[i].x, arr[i].y - 1);
                        if (pixelColor.A == Color.Black.A && pixelColor.R == Color.Black.R && pixelColor.G == Color.Black.G && pixelColor.B == Color.Black.B)
                        {
                            bmp.SetPixel(arr[i].x, arr[i].y - 1, mf.inkColor);
                            newarr[newlength].x = arr[i].x;
                            newarr[newlength].y = arr[i].y - 1;
                            newlength++;
                        }
                    }
                }
                for (int i = 0; i < newlength; i++)
                {
                    arr[i].x = newarr[i].x;
                    arr[i].y = newarr[i].y;
                }
                length = newlength;
            }
        }