Quick/easy way to rotate a Windows bitmap by 90 degrees?
This is a last-ditch effort to work around a buggy printer driver. I want to render to a co开发者_运维知识库mpatible bitmap, then rotate it before or while copying to the printer DC.
I'm familiar with this previous question which recommended GDI+, but I'm curious to know if there's an answer using GDI only.
Either of these techniques should work:
PlgBlt
, which "performs a bit-block transfer of the bits of color data from the specified rectangle in the source device context to the specified parallelogram in the destination device context", with the coordinates of a rotated parallelogramA combination of
SetWorldTransform
, passing in a rotation matrix, and normalBitBlt
.
Note with both these, there should be no rotation transformation in the source DC, only the destination.
I'm afraid I'm not able to give you a code example right now, but some googling did turn up some examples of how to use these functions to rotate an arbitrary number of degrees, which you could modify to hard-code to 90 degrees:
- Using
PlgBlt
(excuse the language here... it's VB) - Using
SetWorldTransform
andBitBlt
. Note that if your code modifies the transformation elsewhere (for example, any VCL'sTGraphicControl
descendant will have this done in itsPaint
method, and it's likely that MFC and other common WinAPI wrappers probably do too) you should useGetWorldTransform
to save the current transformation and apply yours withModifyWorldTransform
rather than setting (overwriting) the current transformation. - While I was looking for those examples, I came across an interesting, very old Microsoft Support question showing how to draw to a rotated or non-rectangular area. I suspect, for rotation, this code is not nearly as good as one of the other functions.
I'm not sure any of these count as quick or easy compared to using GDI+ :)
精彩评论