开发者

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:

  1. 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 parallelogram

  2. A combination of SetWorldTransform, passing in a rotation matrix, and normal BitBlt.

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 and BitBlt. Note that if your code modifies the transformation elsewhere (for example, any VCL's TGraphicControl descendant will have this done in its Paint method, and it's likely that MFC and other common WinAPI wrappers probably do too) you should use GetWorldTransform to save the current transformation and apply yours with ModifyWorldTransform 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+ :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜