您好,登錄后才能下訂單哦!
這篇文章主要講解了“VB.NET中心旋轉(zhuǎn)圖像的實(shí)現(xiàn)方法”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“VB.NET中心旋轉(zhuǎn)圖像的實(shí)現(xiàn)方法”吧!
我們?cè)趯W(xué)習(xí)一門編程語言的時(shí)候,需要通過不斷的實(shí)踐去積累經(jīng)驗(yàn),來加深我們對(duì)這門語言的理解程度。對(duì)于VB.NET的學(xué)習(xí)同樣也是如此。在這里我們先通過一段VB.NET中心旋轉(zhuǎn)圖像的實(shí)現(xiàn)代碼來初步的了解一下這門語言的編寫方式和應(yīng)用方法。
鼠標(biāo)拖拽旋轉(zhuǎn)。實(shí)現(xiàn)任意角度的VB.NET中心旋轉(zhuǎn)圖像。
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)'可以用叉乘求面積,正負(fù)號(hào)代表旋轉(zhuǎn)方向,而后正弦定理求角度,
Dim O As Double = Windows.Vector.AngleBetween(vOB, vOE)
'若角度為有效值
gr.TranslateTransform(bmpsize / 2, bmpsize / 2)
'移動(dòng)坐標(biāo)至圖像中心gr.RotateTransform(O) '按角度旋轉(zhuǎn)
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中心旋轉(zhuǎn)圖像的實(shí)現(xiàn)方法”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)VB.NET中心旋轉(zhuǎn)圖像的實(shí)現(xiàn)方法這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是億速云,小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。