예제 #1
0
        // Done!
        private static void FindEdgesHelper(UnsafeBitmap source, UnsafeBitmap destination, int x, int y, Color pixel, Color edge, Rectangle area, float threshold)
        {
            int sy = y - 1;
            int sx = x - 1;
            int yl = y + 1;
            int xl = x + 1;

            for (int i = sy; i <= yl; ++i)
            {
                for (int k = sx; k <= xl; ++k)
                {
                    if (k == i)
                    {
                        continue;
                    }
                    if (IsValid(k, i, area.Width, area.Height) == false)
                    {
                        continue;
                    }

                    PixelData temp = source.GetPixel(k, i);

                    int dr = temp.Red - pixel.R;
                    int dg = temp.Green - pixel.G;
                    int db = temp.Blue - pixel.B;

                    var distance = Math.Sqrt((dr * dr) + (dg * dg) + (db * db));

                    if (distance > threshold)
                    {
                        destination.SetPixel(x, y, edge);
                        return;
                    }
                }
            }
            destination.SetPixel(x, y, Color.White);
        }
예제 #2
0
        // Done!
        private static Color[] GetNeighbours(UnsafeBitmap source, int x, int y)
        {
            const int offset = 1;
            int       sy     = y - offset;
            int       sx     = x - offset;
            int       yl     = y + offset;
            int       xl     = x + offset;

            Color[] pixelData = new Color[9];

            int counter = 0;

            for (int i = sy; i <= yl; ++i)
            {
                for (int k = sx; k <= xl; ++k)
                {
                    pixelData[counter++] = IsValid(k, i, Area.Width, Area.Height) == false ? EmptyColor : (Color)source.GetPixel(k, i);
                }
            }

            return(pixelData);
        }