title: Search for Pixel on screen
body: <p>I want to find a specific pixel coordinates from screen. Here's my code (I'm mega-super-newbie, I just started today with C#:</p>
  
  <pre><code>static string GetPixel(int X, int Y)
  {
      Point position = new Point(X, Y);
      var bitmap = new Bitmap(1, 1);
      var graphics = Graphics.FromImage(bitmap);
  
      graphics.CopyFromScreen(position, new Point(0, 0), new Size(1, 1));
  
      var _Pixel = bitmap.GetPixel(0, 0);
      return "0x" + _Pixel.ToArgb().ToString("x").ToUpper().Remove(0, 2);
      //it returns a pixel color in a form of "0xFFFFFF" hex code
      //I had NO idea how to convert it to hex code so I did that :P
  }
  
  static void Main()
  {
      // for x = 1 to screen width...
      for (int x = 1; x &lt;= Screen.PrimaryScreen.Bounds.Bottom; x++)
      {
          // for x = 1 and y = 1 to screen height...
          for (int y = 1; y &lt;= Screen.PrimaryScreen.Bounds.Height; y++)
          {
              string pixel = GetPixel(x, y);
              if (pixel == "0x007ACC") //blue color
              {
                  MessageBox.Show("Found 0x007ACC at: (" + x + "," + y + ")");
                  break; //exit loop
              }
          }
      }
  }
  </code></pre>
  
  <p>edit:
  Here's an error which appears when I run this script:</p>
  
  <blockquote>
    <p>An unhandled exception of type 'System.ArgumentOutOfRangeException'
    occurred in mscorlib.dll</p>
    
    <p>Additional information: Index and length must refer to a location
    within the string</p>
  </blockquote>
  
  <p>I have experience in AutoIt, it's my first day with C# ^^
  Regards</p>