title: Read pixels from a HDC
body: <p>I'm trying to read all pixels on a given area of a HDC to find if a color is present, currently I came up with:</p>
  <pre><code>IDirect3DSurface9* pSurface = 0;
  p1-&gt;CreateOffscreenPlainSurface(1280, 1024,D3DFMT_A8R8G8B8, D3DPOOL_SYSTEMMEM, &amp;pSurface, NULL);
  p1-&gt;GetFrontBufferData(0, pSurface);
  //assert( pSurface );
  if( pSurface &amp;&amp; GetTickCount() &gt; dwGAKS_Fix )
  {
      HDC dc;
      pSurface-&gt;GetDC( &amp;dc );
      COLORREF dpurp = D3DCOLOR_ARGB (255,102,0 ,153);
      for( DWORD h = 610; h &lt;= 670; h++ )
      {
          for( DWORD w = 480; w&lt;=530; w++ )
          {
              COLORREF dwPixel = GetPixel( dc, h, w );
          //  CString strPixel; strPixel.Format( &quot;Pixel col: %u at: %u X %u&quot;, dwPixel, d, i );
              //if( dx_Font )
              if( dwPixel == dpurp )
              {
                  dx_Font-&gt;DrawTextA(NULL, &quot;Shoot&quot;, strlen(&quot;Shoot&quot;), &amp;pos, DT_NOCLIP, D3DCOLOR_XRGB(0, 255, 0));
              }
              else
                  dx_Font-&gt;DrawTextA(NULL, &quot;NoShoot&quot;, strlen(&quot;NoShoot&quot;), &amp;pos, DT_NOCLIP, D3DCOLOR_XRGB(0, 255, 0));
          }
      }
      dwGAKS_Fix = GetTickCount() + 15;
      pSurface-&gt;ReleaseDC( dc );
      pSurface-&gt;Release();
  </code></pre>
  <p>But this solution is slow, very slow, I need something somewhat more..uh professional</p>
  <h1>edit</h1>
  <pre><code>D3DLOCKED_RECT d3dlocked;
                  if( D3D_OK == pSurface-&gt;LockRect( &amp;d3dlocked, 0, 0 ) )
                  {
                      UINT *pixels=(UINT *)locked.pBits;
                      if(pixels[52+15*1024]&amp;0xFFFFFF00==dpurp)
                      {
                          
                      }
  
                      pSurface-&gt;UnlockRect();
                  }
  </code></pre>