Option Explicit
Const Pi = 3.14
Dim flag As String
Private Sub Command1_Click()
Dim x As Integer, y As Integer '点在Picture1中的坐标
Dim X1 As Integer, Y1 As Integer '过渡坐标
Dim X2 As Double, Y2 As Double '过渡坐标
Dim X3 As Double, Y3 As Double '点经过旋转后在Picture2中的坐标
Dim angle As Double '旋转的角度
Dim radian As Double '旋转的弧度
If flag = "ni" Then
angle = Text1.Text
'获得旋转的角度
ElseIf flag = "shun" Then
angle = 360 - Text1.Text
End If
radian = angle * Pi / 180
'获得旋转的弧度
Picture2.Cls
For x = 0 To Picture1.Width
For y = 0 To Picture1.Height
X1 = x - Picture1.Width \ 2
Y1 = y - Picture1.Height \ 2
'将坐标轴原点移动到Picture1的中心后原来坐标为(x,y)
'的点的新坐标为(X1,Y1)
X2 = X1 * Cos(radian) + Y1 * Sin(radian)
'获得在更改坐标原点后旋转后该点的X坐标
Y2 = Y1 * Cos(radian) - X1 * Sin(radian)
'获得在更改坐标原点后旋转后该点的Y坐标
X3 = X2 + Picture1.Width \ 2
'获得恢复坐标原点后旋转后的X坐标
Y3 = Y2 + Picture1.Height \ 2
'获得恢复坐标原点后旋转后的Y坐标
Picture2.Visible = True
If X3 > 0 And X3 < Picture2.Width - 1 And Y3 > 0 _
And Y3 < Picture2.Height - 1 Then
Picture2.PSet (X3, Y3), Picture1.Point(x, y)
'将picture1中的点复制到picture2中
End If
'Picture1.PSet (x, y), Picture2.Point(X3, Y3)
Next y
Next x
End Sub
'import System.Drawing
Private Sub Command2_Click()
'Dim x As Integer
'Dim y As Integer
'Dim c As Point ( 0,0)
If flag = "da" Then
'将图像放大2倍
Dim i, j As Integer
Picture2.Width = Picture1.Width * 2
Picture2.Height = Picture1.Height * 2
For i = 0 To Picture2.Width * 2 - 1 Step 2
For j = 0 To Picture2.Height * 2 - 1 Step 2
Picture2.PSet (i, j), Picture1.Point(i / 2, j / 2)
Picture2.PSet (i + 1, j), Picture1.Point(i / 2, j / 2)
Picture2.PSet (i, j + 1), Picture1.Point(i / 2, j / 2)
Picture2.PSet (i + 1, j + 1), Picture1.Point(i / 2, j / 2)
Next
Next
End If
End Sub
Private Sub Option1_GotFocus()
flag = "shun"
End Sub
Private Sub Option2_GotFocus()
flag = "ni"
End Sub
Private Sub Check1_GotFocus()
flag = "da"
End Sub
- 1
- 2
前往页