旋转picturebox中的图像
原来写打飞机游戏时想让飞机任意角度旋转,就写了这个,比较简单。因为纯以像素点为对象,速度不理想,没用上。也没再考虑,看大家是否感兴趣,可以交流。窗体代码
程序代码:Option Explicit
Private Sub Command1_Click()
Dim x, y As Integer
Dim x0, y0, x1, y1 As Integer
Dim zoom As Single '缩小倍数
zoom = 1
'以图片中心为圆心旋转
x0 = Picture1.Width / 2
y0 = Picture1.Height / 2
For x1 = 0 To Picture1.Width
For y1 = 0 To Picture1.Height
x = rotate_point(x0, y0, x1, y1, 0, rotate).x + 200
y = rotate_point(x0, y0, x1, y1, 0, rotate).y + 200
Form1.PSet (x / zoom, y / zoom), Picture1.Point(x1, y1)
Next
Next
rotate = rotate + 10
End Sub模块代码
程序代码:'coordinate type Option Explicit Type coodinate x As Integer y As Integer End Type Public rotate As Single 'function return x and y Function rotate_point(x0, y0, x1, y1 As Integer, direction As Boolean, angle As Single) As coodinate 'center point(x0,y0) end point(x1,y1) direction=0 clockwise direction=1 counterclockwise Dim temp, r As Single r = ((y1 - y0) ^ 2 + (x1 - x0) ^ 2) ^ 0.5 If (x1 - x0) <> 0 Then temp = Atn((y1 - y0) / (x1 - x0)) If x1 < x0 Then temp = temp + 3.14 If x1 > x0 And y1 < y0 Then temp = temp + 6.28 temp = temp + ((-1) ^ direction) * (3.14 * angle / 180) If temp > 6.28 Then temp = temp - 6.28 If temp < 0 Then temp = temp + 6.28 rotate_point.x = x0 + r * Cos(temp) rotate_point.y = y0 + r * Sin(temp) End Function






