这篇文章主要讲解了“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进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。