您好,登錄后才能下訂單哦!
這篇文章主要講解了“VB.NET中心旋轉圖像的實現方法”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“VB.NET中心旋轉圖像的實現方法”吧!
我們在學習一門編程語言的時候,需要通過不斷的實踐去積累經驗,來加深我們對這門語言的理解程度。對于VB.NET的學習同樣也是如此。在這里我們先通過一段VB.NET中心旋轉圖像的實現代碼來初步的了解一下這門語言的編寫方式和應用方法。
鼠標拖拽旋轉。實現任意角度的VB.NET中心旋轉圖像。
Public Class Form1
Dim bmp As Bitmap
Dim bmpsize As Single
Dim gr As Graphics
Dim pb As Point
Dim po As PointF
Private Sub Form1_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles MyBase.Loadbmpsize = Math.Sqrt(Me.Icon.Width ^
2 + Me.Icon.Height ^ 2)bmp = New Bitmap(CInt(bmpsize), CInt(bmpsize))
gr = Graphics.FromImage(bmp)
po = New PointF((bmpsize - Me.Icon.Width)
/ 2, (bmpsize - Me.Icon.Height) / 2)gr.DrawIcon(Me.Icon, po.X, po.Y)
PictureBox1.Image = bmp
End Sub
Private Sub PictureBox1_MouseDown(ByVal
sender As Object, ByVal e As System.Windows.
Forms.MouseEventArgs) Handles PictureBox1.MouseDownpb = e.Location
End Sub
Private Sub PictureBox1_MouseMove(ByVal
sender As Object, ByVal e As System.Windows.
Forms.MouseEventArgs) Handles PictureBox1.MouseMoveIf Not pb = Point.Empty Then
'O\-----------B
' \
' \
' \
' E
Dim vOB, vOE As Windows.Vector
vOB = New Windows.Vector(bmpsize / 2,
bmpsize / 2) - New Windows.Vector(pb.X, pb.Y)vOE = New Windows.Vector(bmpsize / 2, bmpsize / 2)
- New Windows.Vector(e.X, e.Y)'可以用叉乘求面積,正負號代表旋轉方向,而后正弦定理求角度,
Dim O As Double = Windows.Vector.AngleBetween(vOB, vOE)
'若角度為有效值
gr.TranslateTransform(bmpsize / 2, bmpsize / 2)
'移動坐標至圖像中心gr.RotateTransform(O) '按角度旋轉
gr.TranslateTransform(-bmpsize / 2, -bmpsize / 2)
'移回gr.Clear(Color.Transparent) '清除原有圖像
gr.DrawIcon(Me.Icon, po.X, po.Y) '繪制新圖像
PictureBox1.Image = bmp
pb = e.Location
End If
End Sub
Private Sub PictureBox1_MouseUp(ByVal sender As
Object, ByVal e As System.Windows.Forms.MouseEventArgs)
Handles PictureBox1.MouseUppb = Point.Empty
End Sub
End Class
感謝各位的閱讀,以上就是“VB.NET中心旋轉圖像的實現方法”的內容了,經過本文的學習后,相信大家對VB.NET中心旋轉圖像的實現方法這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。