Note that there are some explanatory texts on larger screens.

plurals
  1. POMore efficient way of scanning the screen for a specific color?
    primarykey
    data
    text
    <p>I currently have the following code which will take a screenshot and check each pixel one at a time if it matches the color I have specified. If it matches then it will move the mouse to the specific pixel location.</p> <p>I am currently looking for a better and faster way of doing this if anybody is able to help out.</p> <p>If you don't want to read the entire code I will explain the process right here: Basically the program will take a screenshot, and analyze it 1 pixel at a time comparing it to the desired color. It will start in the top left pixel and horizontally moving down one row at a time and if it was unable to find the pixel it will restart. This code also will only work for a 1080p screen which is fine for me.</p> <p>Now the code WORKS I am just looking for a more efficient way than scanning 2 Million + pixels.</p> <pre><code>Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height); Graphics graphics = Graphics.FromImage(bitmap as Image); graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size); bool found = false; bool one = true; bool two = false; int x = 0; int y = 0; Bitmap myBitmap = bitmap; while (found != true) { Color pixelColor = myBitmap.GetPixel(x, y); if (pixelColor == Color.FromArgb(0, 0, 0)) { Cursor.Position = new Point(x, y); found = true; } if (one == true) { x = x + 1; if (x &gt;= 1920) { one = false; two = true; x = 0; } } else if (two == true) { y = y + 1; if (y &gt;= 1080) { y = 0; } one = true; two = false; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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