Exemplo n.º 1
0
        public static Point[] Search(Rectangle rect, Color Pixel_Color, int Shade_Variation)
        {
            System.Collections.ArrayList points = new System.Collections.ArrayList();
            Bitmap     GetScreenShot            = ScreenEx.GetScreenCapture(rect);
            BitmapData RegionIn_BitmapData      = GetScreenShot.LockBits(new Rectangle(0, 0, GetScreenShot.Width, GetScreenShot.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);

            int[] Formatted_Color = new int[3] {
                Pixel_Color.B, Pixel_Color.G, Pixel_Color.R
            };

            unsafe
            {
                for (int y = 0; y < RegionIn_BitmapData.Height; y++)
                {
                    byte *row = (byte *)RegionIn_BitmapData.Scan0 + (y * RegionIn_BitmapData.Stride);
                    for (int x = 0; x < RegionIn_BitmapData.Width; x++)
                    {
                        if (row[x * 3] >= (Formatted_Color[0] - Shade_Variation) & row[x * 3] <= (Formatted_Color[0] + Shade_Variation))                     //blue
                        {
                            if (row[(x * 3) + 1] >= (Formatted_Color[1] - Shade_Variation) & row[(x * 3) + 1] <= (Formatted_Color[1] + Shade_Variation))     //green
                            {
                                if (row[(x * 3) + 2] >= (Formatted_Color[2] - Shade_Variation) & row[(x * 3) + 2] <= (Formatted_Color[2] + Shade_Variation)) //red
                                {
                                    points.Add(new Point(x + rect.X, y + rect.Y));
                                }
                            }
                        }
                    }
                }
            }
            GetScreenShot.Dispose();
            return((Point[])points.ToArray(typeof(Point)));
        }
Exemplo n.º 2
0
        public static Point[] Search(Rectangle rect, Color pixelColor, int shadeVariation)
        {
            var points             = new List <Point>();
            var getScreenShot      = ScreenEx.GetScreenCapture(rect);
            var regionInBitmapData =
                getScreenShot.LockBits(new Rectangle(0, 0, getScreenShot.Width, getScreenShot.Height),
                                       ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb);
            var formattedColor = new int[] { pixelColor.B, pixelColor.G, pixelColor.R };

            unsafe
            {
                for (var y = 0; y < regionInBitmapData.Height; y++)
                {
                    var row = (byte *)regionInBitmapData.Scan0 + (y * regionInBitmapData.Stride);
                    for (var x = 0; x < regionInBitmapData.Width; x++)
                    {
                        if (!(row[x * 3] >= (formattedColor[0] - shadeVariation) &
                              row[x * 3] <= (formattedColor[0] + shadeVariation)))
                        {
                            continue;
                        }
                        if (!(row[(x * 3) + 1] >= (formattedColor[1] - shadeVariation) &
                              row[(x * 3) + 1] <= (formattedColor[1] + shadeVariation)))
                        {
                            continue;
                        }
                        if (row[(x * 3) + 2] >= (formattedColor[2] - shadeVariation) &
                            row[(x * 3) + 2] <= (formattedColor[2] + shadeVariation)) //red
                        {
                            points.Add(new Point(x + rect.X, y + rect.Y));
                        }
                    }
                }
            }

            getScreenShot.Dispose();
            return(points.ToArray());
        }