我正在做一个停车场游戏。我正在使用箭头键移动它,但是当按下向下键时,图片框不会向下移动。而且,当按下向右或向上键时,图片盒子没有停止。我想在向右或向左移动的同时旋转汽车。我试过但是没能。
Private Sub Timerdiagonalright_Tick(sender As Object, e As EventArgs) Handles Timerdiagonalright.Tick
RotateImage(pbcar1.Image, 20)
End Sub
Private Function RotateImage(img As Image, angle As Single) As Bitmap
' the calling code is responsible for (and must)
' disposing of the bitmap returned
Dim retBMP As New Bitmap(img.Width, img.Height)
retBMP.SetResolution(img.HorizontalResolution, img.VerticalResolution)
Using g = Graphics.FromImage(retBMP)
' rotate aroung the center of the image
g.TranslateTransform(img.Width \ 2, img.Height \ 2)
'rotate
g.RotateTransform(angle)
g.TranslateTransform(-img.Width \ 2, -img.Height \ 2)
'draw image to the bitmap
g.DrawImage(img, New PointF(0, 0))
Return retBMP
End Using
End Function
答案 0 :(得分:0)
如果图片已经加载到PictureBox,您可以使用
PictureBox.Image.RotateFlip(RotateFlipType)
旋转图像。
请注意,这不是制作动画图形的有效方法;在移动控件时稍微提高性能,请考虑阅读SuspendLayout / ResumeLayout和BeginUpdate / EndUpdate。