title: Trouble converting a JPEG encoded BITMAP into a Gdiplus::Bitmap object
body: <p>I'm using c++ to do some image work and I'd like to be able to work with jpeg compressed files.  The GDI+ library appears to have what I need, and specifically the Gdiplus::Bitmap::GetPixel() routine is what I'd ultimately like to use.  </p>
  
  <p>There are several Gdiplus::Bitmap constructors, and the one I'd like to use takes in a BITMAPINFO structure and a pointer to the image bits. <a href="http://msdn.microsoft.com/en-us/library/ms536312%28v=vs.85%29.aspx" rel="nofollow">Bitmap.Bitmap(const BITMAPINFO* lpbmi, VOID* lpbits) </a>  I already have this information from a hooked<a href="http://msdn.microsoft.com/en-us/library/dd145121%28v=vs.85%29.aspx" rel="nofollow"> StretchDIBits() </a> So I'm not even creating the original BITMAP, its being given to me. But the compression is set for <strong>JPEG</strong> on the bitmap <a href="http://msdn.microsoft.com/en-us/library/dd183376%28v=vs.85%29.aspx" rel="nofollow"> (BITMAPINFO.BITMAPINFOHEADER.biCompression = BI_JPEG) </a>, so its not easy to parse, and I don't know how, or want to write a jpeg decompression algorithm.</p>
  
  <p>The following is the code i'm using to try to leverage the GDI+ libraries to allow me to look at individual pixels in a jpeg compressed image:</p>
  
  <pre><code>// lpbmi and lpBits come from a hooked StretchDIBits call. I did not generate this data.
  // The following is some sample data that i've seen go in and not work:
  //
  // lpbmi-&gt;bmiHeader.biSize = 40 
  // lpbmi-&gt;bmiHeader.biWidth = 1299 
  // lpbmi-&gt;bmiHeader.biHeight = -1 
  // lpbmi-&gt;bmiHeader.biPlanes = 1 
  // lpbmi-&gt;bmiHeader.biBitCount = 0 
  // lpbmi-&gt;bmiHeader.biCompression = 4        // resolves to BI_JPEG 
  // lpbmi-&gt;bmiHeader.biSizeImage = 955 
  // lpbmi-&gt;bmiHeader.biXpelsPerMeter = 0 
  // lpbmi-&gt;bmiHeader.biYpelsPerMeter = 0 
  // lpbmi-&gt;bmiHeader.biClrUsed = 0 
  // lpbmi-&gt;bmiHeader.biClrImportant = 0 
  //
  // This data looks valid to me, so i don't know why nothing happens when trying to convert
  // it into a Gdiplus::Bitmap
  void SomeMethod(const BITMAPINFO * lpbmi, const void * lpBits)
  {
      // Apparently, this is needed before using GDI+ libraries. I experimented
      // without this and nothing different happend.  Not even a crash.
      GdiplusStartupInput gdiplusStartupInput;
      ULONG_PTR gdiplusToken;
      GdiplusStartup(&amp;gdiplusToken, &amp;gdiplusStartupInput, NULL);
  
      // Because the BitmapClass doesn't take in a (const void *), I have to copy the data
      // into another array.  Not much i can do about it because i'm given lpBits as a
      // (const void *)
      void * data = malloc(lpbmi-&gt;bmiHeader.biSizeImage);
      memcpy(data, lpBits, lpbmi-&gt;bmiHeader.biSizeImage);
  
      // I "expect" that this bascially reads in the data provided and creates our
      // Bitmap class.
      Bitmap bitmap(lpbmi, data);
  
      // The problem is, Width and Height are always 0.  Can't figure out why.
      UINT Width = bitmap-&gt;GetWidth();        // Why always 0????
      UINT Height = bitmap-&gt;GetHeight();      // Why always 0????
  
      //////////////////////
      // Some more code ...
      //////////////////////
  }
  </code></pre>
  
  <p>Anyone have any ideas why the Gdiplus::Bitmap class isn't doing anything with the data I'm giving it?</p>