VB.NET中心旋转图像实现技巧分享

开发 后端
VB.NET中心旋转图像的实现,完全可以按照本文给出的这段代码进行操作。初学者们可以以此为参考,进行实际编写,以加深对此的了解。

 

我们在学习一门编程语言的时候,需要通过不断的实践去积累经验,来加深我们对这门语言的理解程度。对于VB.NET的学习同样也是如此。在这里我们先通过一段VB.NET中心旋转图像的实现代码来初步的了解一下这门语言的编写方式和应用方法。

 

 

 

鼠标拖拽旋转。实现任意角度的VB.NET中心旋转图像。

 

 

 

  1. Public Class Form1  
  2. Dim bmp As Bitmap  
  3. Dim bmpsize As Single  
  4. Dim gr As Graphics  
  5. Dim pb As Point  
  6. Dim po As PointF  
  7. Private Sub Form1_Load(ByVal sender As 
    System.Object, ByVal e As System.EventArgs)
     Handles MyBase.Load  
  8. bmpsize = Math.Sqrt(Me.Icon.Width ^ 
    2 + Me.Icon.Height ^ 2)  
  9. bmp = New Bitmap(CInt(bmpsize), CInt(bmpsize))  
  10. gr = Graphics.FromImage(bmp)  
  11. po = New PointF((bmpsize - Me.Icon.Width) 
    / 2, (bmpsize - Me.Icon.Height) / 2)  
  12. gr.DrawIcon(Me.Icon, po.X, po.Y)  
  13. PictureBox1.Image = bmp 
  14. End Sub  
  15. Private Sub PictureBox1_MouseDown(ByVal 
    sender As Object, ByVal e As System.Windows.
    Forms.MouseEventArgs) Handles PictureBox1.MouseDown  
  16. pb = e.Location  
  17. End Sub  
  18. Private Sub PictureBox1_MouseMove(ByVal 
    sender As Object, ByVal e As System.Windows.
    Forms.MouseEventArgs) Handles PictureBox1.MouseMove  
  19. If Not pb = Point.Empty Then  
  20. 'O\-----------B  
  21. ' \   
  22. ' \  
  23. ' \  
  24. ' E  
  25. Dim vOB, vOE As Windows.Vector  
  26. vOB = New Windows.Vector(bmpsize / 2, 
    bmpsize / 2) - New Windows.Vector(pb.X, pb.Y)  
  27. vOE = New Windows.Vector(bmpsize / 2, bmpsize / 2)
     - New Windows.Vector(e.X, e.Y)  
  28. '可以用叉乘求面积,正负号代表旋转方向,而后正弦定理求角度,  
  29. Dim O As Double = Windows.Vector.AngleBetween(vOB, vOE)  
  30. '若角度为有效值  
  31. gr.TranslateTransform(bmpsize / 2, bmpsize / 2) 
    '移动坐标至图像中心  
  32. gr.RotateTransform(O) '按角度旋转  
  33. gr.TranslateTransform(-bmpsize / 2, -bmpsize / 2)
     '移回  
  34. gr.Clear(Color.Transparent) '清除原有图像  
  35. gr.DrawIcon(Me.Icon, po.X, po.Y) '绘制新图像  
  36. PictureBox1.Image = bmp 
  37. pb = e.Location  
  38. End If  
  39. End Sub  
  40. Private Sub PictureBox1_MouseUp(ByVal sender As 
    Object, ByVal e As System.Windows.Forms.MouseEventArgs) 
    Handles PictureBox1.MouseUp  
  41. pb = Point.Empty  
  42. End Sub  
  43. End Class 

VB.NET中心旋转图像的具体操作方法就为大家介绍到这里,希望对大家有所帮助。

责任编辑:曹凯 来源: CSDN
相关推荐

2010-01-18 18:50:26

VB.NET鼠标手势

2010-01-18 16:33:57

VB.NET加密文件

2010-01-07 13:40:50

VB.NET读取XML

2010-01-14 16:04:32

VB.NET显示时间

2010-01-18 16:41:47

VB.NET用户登录页

2010-01-15 19:04:09

2010-01-22 11:02:30

VB.NET创建新变量

2010-01-13 15:52:59

VB.NET浮动窗体

2010-01-22 13:16:05

VB.NET初始化数组

2010-01-13 16:45:44

VB.NET删除控件

2010-01-11 15:31:04

VB.NET拖动窗体

2010-01-08 18:31:45

VB.NET历史菜单

2010-01-19 15:30:44

VB.NET比较运算符

2010-01-22 16:27:19

VB.NET关于对话框

2010-01-15 19:24:42

2010-01-13 10:25:30

VB.NET文件夹操作

2010-01-07 10:02:53

Flash控制VB.N

2010-01-11 16:04:10

VB.NET使用wit

2010-01-13 14:41:18

VB.NET列出目录内

2010-01-18 19:36:52

VB.NET调整控件
点赞
收藏

51CTO技术栈公众号