Note that there are some explanatory texts on larger screens.

plurals
  1. POColor on screen area search
    text
    copied!<p>I'm trying to find patches of a certain color on the screen.</p> <p>I am able to find all the pixels on the screen and test the RGB and add the points into an array, but i don't want all the pixels just 1 point for each patch of the color.</p> <p>Here is my code:</p> <pre><code> public static Point[] PixelSearch(Rectangle rect, Color Pixel_Color, int Shade_Variation) { ArrayList points = new ArrayList(); Bitmap RegionIn_Bitmap = new Bitmap(rect.Width, rect.Height, PixelFormat.Format24bppRgb); using (Graphics GFX = Graphics.FromImage(RegionIn_Bitmap)) { GFX.CopyFromScreen(rect.X, rect.Y, 0, 0, rect.Size, CopyPixelOperation.SourceCopy); } BitmapData RegionIn_BitmapData = RegionIn_Bitmap.LockBits(new Rectangle(0, 0, RegionIn_Bitmap.Width, RegionIn_Bitmap.Height), ImageLockMode.ReadWrite, PixelFormat.Format24bppRgb); int[] Formatted_Color = new int[3] { Pixel_Color.B, Pixel_Color.G, Pixel_Color.R }; //bgr unsafe { for (int y = 0; y &lt; RegionIn_BitmapData.Height; y++) { byte* row = (byte*)RegionIn_BitmapData.Scan0 + (y * RegionIn_BitmapData.Stride); for (int x = 0; x &lt; RegionIn_BitmapData.Width; x++) if (row[x * 3] &gt;= (Formatted_Color[0] - Shade_Variation) &amp; row[x * 3] &lt;= (Formatted_Color[0] + Shade_Variation)) //blue if (row[(x * 3) + 1] &gt;= (Formatted_Color[1] - Shade_Variation) &amp; row[(x * 3) + 1] &lt;= (Formatted_Color[1] + Shade_Variation)) //green if (row[(x * 3) + 2] &gt;= (Formatted_Color[2] - Shade_Variation) &amp; row[(x * 3) + 2] &lt;= (Formatted_Color[2] + Shade_Variation)) //red points.Add(new Point(x + rect.X, y + rect.Y)); } } RegionIn_Bitmap.Dispose(); return (Point[])points.ToArray(typeof(Point)); } </code></pre> <p>I call the method like this:</p> <pre><code>points = PixelSearch(Screen.PrimaryScreen.Bounds, Color.FromArgb(255, 0, 0), 15); </code></pre> <p>I sometimes get thousands of results from this and would only like a few. any ideas how i can do this?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload