title: Delphi/C++Builder TBitmap: How to determinine scanline order?
body: <p>Delphi's TBitmap type is basically a wrapper over a GDI BITMAP and PALETTE, and can support both top-down and bottom-up scanline ordering.</p>
  
  <p>I have a TBitmap which I need to convert to GDI+ Bitmap, in order to rotate and composite it.</p>
  
  <p>My bitmap is 32-bit ARGB, which windows supports, but VCL doesn't natively 'understand'. </p>
  
  <pre><code>TBitmap *bmp;
  ...
  </code></pre>
  
  <p>When I use the following constructor, the alpha channel doesn't work for compositing, but otherwise everything works.</p>
  
  <pre><code>Gdiplus::Bitmap b(bmp-&gt;Handle, NULL);
  </code></pre>
  
  <p>So, I tried the constructor below, which takes size, pixel data and format params.</p>
  
  <pre><code>Gdiplus::Bitmap b(bmp-&gt;Width,  bmp-&gt;Height, bmp-&gt;Width *4, PixelFormat32bppARGB,   
      (BYTE*) bmp-&gt;ScanLine[bmp-&gt;Height-1]); // bottom up storage
  </code></pre>
  
  <p>This gets the alpha, but the bitmap is upside down, so I tried this</p>
  
  <pre><code>Gdiplus::Bitmap b(bmp-&gt;Width,  bmp-&gt;Height, - bmp-&gt;Width *4, PixelFormat32bppARGB,   
      (BYTE*) bmp-&gt;ScanLine[0]);  // negative stride for bottom up bitmaps?!
  </code></pre>
  
  <p>Now, that works, but of course I'm hard-coded into bottom-up bitmaps. However, I can't find a way of determining if the TBitmap is top-down or bottom-up. They're stored internally with negative height but the height value is massaged before it's passed back to user code.</p>
  
  <p>How can I find out the scanline ordering, or - better yet - is there another way of creating a GDIPlus bitmap from a TBitmap?</p>