How to rotate Bitmap in windows GDI?

隐身守侯 提交于 2019-11-30 01:57:04

问题


How would I go about rotating a Bitmap in Windows GDI,C++?


回答1:


You can do it with GDI+ (#include <gdiplus.h>). The Graphics class has the RotateTransform method. That allows arbitrary rotations. Use Image::RotateFlip() if you only need to rotate by 90 degree increments, that's a lot more efficient.




回答2:


Sounds like you have to use PlgBlt. Take your rectangle's 4 corners as 2D Points, rotate them, then call PlgBlt.

From MSDN Bitmap Rotation:

To copy a bitmap into a parallelogram; use the PlgBlt function, which performs a bit-block transfer from a rectangle in a source device context into a parallelogram in a destination device context. To rotate the bitmap, an application must provide the coordinates, in world units, to be used for the corners of the parallelogram.




回答3:


Another possibility (beyond those already suggested) is to use SetWorldTransform(). This is different in that it is modal and applies to the DC as a whole, not just a single operation. If you want to rotate one bitmap rotated, but other things without rotation, it's probably not your best choice. If you want to draw a number of things rotated, or (especially) if you want to rotate everything you draw (at least into one DC) it can work quite nicely though.



来源:https://stackoverflow.com/questions/2270110/how-to-rotate-bitmap-in-windows-gdi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!