title: Using Gdiplus to get pixel value of an image
body: <p>This is quite a simple thing, but I am not really trained in C++. I just need to get each pixel value of an image. Let us say that it is "C:\LM3S811\red.bmp", 169x104 pixel. </p>
  
  <p>By googling around the topic, I am convinced that gdiplus from Microsoft SDK should be able to do this. Below is my code to get red value of each pixel:   </p>
  
  <pre><code>    #include &lt;iostream&gt;
      #include &lt;windows.h&gt;
      #include &lt;gdiplus.h&gt;
      using namespace Gdiplus;
      using namespace std;
      #pragma comment (lib, "Gdiplus.lib")
  
      int main(){
  
          // set bitmap to "C:\LM3S811\red.bmp"
          Bitmap myBitmap (L"C:\\LM3S811\\red.bmp");
  
          Color pixelColor;
  
          // print red value of each pixel of 169x104 pixel
          for (int y = 1; y &lt;= 104; y++){
              for (int x = 1; x &lt;= 169; x++){
                  myBitmap.GetPixel(x, y, &amp;pixelColor);
                  cout &lt;&lt; (int)pixelColor.GetRed() &lt;&lt; ",";
              }
          }
  
          // end
          cout &lt;&lt; endl;
          system("PAUSE");
          return 0;
      }
  </code></pre>
  
  <p>When I run the code, it always gives zero for all pixels. If I deliberately set <code>pixelColor</code> by doing i.e. <code>Color pixelColor(0, 255, 255, 255);</code> instead, then it will give the correct value 255. Seems <code>myBitmap.GetPixel(x, y, &amp;pixelColor);</code> does not return <code>pixelColor</code> correctly. Please let me know the mistake of the code above.</p>
  
  <p>Your help is really appreciated. Thanks! </p>