Mike Versteeg wrote:
I draw using whatever drawing method works best, usually
Canvas->Draw. What does it matter? But it's great VCL drawing looks
at orientation, exactly what I want! However I still don't know how
to flag a bitmap orientation, am I missing the obvious?
You missed my point. This is not a VCL issue, it is a Win32 issue. A
bitmap knows its own orientation, it is specified in the bitmap's
header:
Top-Down vs. Bottom-Up DIBs
https://msdn.microsoft.com/en-us/library/windows/desktop/dd407212.aspx
Drawing functions at the OS layer are aware of this orientation so they
can process the pixels correctly.
You say you are memcpy'ing pixel data, which means you are accessing
the bitmap's raw scanline data, so your pixel data must match the
bitmap's orientation. If you create a bottom-up bitmap and fill it
with top-down data, the bitmap will render upside down.
Bitmaps are bottom-up by default. If you have top-down pixel data, you
need to create a top-down bitmap before you then fill it with top-down
pixel data. Otherwise, you have to reverse your top-down pixel data
when filling a bottom-up bitmap.
To create a top-down TBitmap, you have to first create a top-down
HBITMAP with the Win32 API, then you can assign it to the
TBitmap::Handle property.
On the other hand, you don't need to worry about orientation at all if
you copy the pixel data scanline-by-scanline instead of all at one
time. The TBitmap::Scanline property takes orientation into account.
Scanline[0] is always the first row of the bitmap, whether it is the
bottom row in a bottom-up bitmap or the top row in a top-down bitmap.
And Scanline[Height-1] is always the last row of the bitmap, whether it
is the top row in a bottom-up bitmap or the bottom row in a top-down
bitmap.
--
Remy Lebeau (TeamB)
Connect with Us