How do I draw a bitmap to a DC, while rotating it by a specified angle?
I'm not sure that this is the best way of doing it, but one option would be to convert it to a wx.Image with ConvertToImage (wxWidgets help) and then use the rotate function (wxWidgets help). You could then (if necessary) convert it back with ConvertToBitmap (wxWidgets help).
I couldn't see an obvious function that could be used to apply a coordinate transform to the drawing context (DC), but there may be one in there somewhere...
Hope that helps.
I agree with Al - he deserves the answer, but this (admittedly untested) code fragment should do what you asked for:
def write_bmp_to_dc_rotated( dc, bitmap, angle ):
'''
Rotate a bitmap and write it to the supplied device context.
'''
img = bitmap.ConvertToImage()
img_centre = wx.Point( img.GetWidth()/2, img.GetHeight()/2 )
img = img.Rotate( angle, img_centre )
dc.WriteBitmap( img.ConvertToBitmap(), 0, 0 )
One thing to note though from the docs:
...using wxImage is the preferred way to load images in wxWidgets, with the exception of resources...
Was there a particular reason to load it as a bitmap rather than a wx.Image?
i think better way if you want a generic rotation e.g. rorate bitmap or text or any other drawing path use Graphics context
gc = wx.GCDC(dc)
gc.Rotate(angle)
gc.DrawText("anurag", 100, 100)