I'm trying to rotate a picture box called player1 with the following command
e.Graphics.RotateTransform(angle)
e.Graphics.DrawImage(BMP, New Point(-player1.Width \ 2, -player1.Height \ 2))
player1.Refresh()
However it seems to place the picture that i have drawn outside the picture box near the top left of the picturebox, i believe that is the current origin. Also, it only rotates about the origin located at the top left. I would like to set the rotation point / origin of the picture box to the centre. Thanks!
I would like to set the rotation point / origin of the picture box to the centre.
Just use TranslateTransform before you rotate:
e.Graphics.TranslateTransform(player1.Width / 2, player1.Height / 2)
e.Graphics.RotateTransform(angle)
e.Graphics.DrawImage(BMP, New Point(-player1.Width \ 2, -player1.Height \ 2))
Depending on what operations you had done previously with e.Graphics
, sometimes you have to ResetTransform()
to put things back to the way they were at the beginning of the Paint() event before you Translate/Rotate/Draw.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.