实例115百叶窗效果
程序员文章站
2022-06-01 16:55:19
...
Graphics.DrawImage 方法
DrawImage(Image, Point) |
在指定的位置使用原始物理大小绘制指定的 Image。 |
DrawImage(Image, Rectangle, Rectangle, GraphicsUnit) |
在指定位置并且按指定大小绘制指定的 Image 的指定部分。 第一个参数是要绘制的图像; 第二个参数是要绘制图像的指定目标区域: 第三个参数要绘制的源图像的指定部分: 第四个参数为图像最单位。 |
Public Class Form1
Dim pic As Image
Dim myGraph As Graphics
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myGraph = PictureBox1.CreateGraphics
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
dlgOpen.Filter = "图片文件|*.bmp;jpg|所有文件|*.*"
If dlgOpen.ShowDialog = DialogResult.OK Then
pic = Image.FromFile(dlgOpen.FileName)
myGraph.DrawImage(pic, New Point(0, 0))
End If
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Timer1.Start()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Me.Close()
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
PictureBox1.Image = Nothing
Dim picLine As Integer = 0
Dim h As Integer = 10
Dim desRect As New Rectangle
Dim srcRect As New Rectangle
Dim i As Long
Dim lnNum As Integer
For lnNum = 0 To 38 Step 2
With srcRect
.X = 0
.Y = lnNum * h
.Width = pic.Width
.Height = h
End With
With desRect
.X = 0
.Y = lnNum * Me.PictureBox1.Height / 40
.Width = PictureBox1.Width
.Height = PictureBox1.Height / 40
End With
myGraph.DrawImage(pic, desRect, srcRect, GraphicsUnit.Pixel)
'延时
For i = 0 To 10000000
Next
Next
For lnNum = 1 To 39 Step 2
With srcRect
.X = 0
.Y = lnNum * h
.Width = pic.Width
.Height = h
End With
With desRect
.X = 0
.Y = lnNum * Me.PictureBox1.Height / 40
.Width = PictureBox1.Width
.Height = PictureBox1.Height / 40
End With
myGraph.DrawImage(pic, desRect, srcRect, GraphicsUnit.Pixel)
'延时
For i = 0 To 10000000
Next
Next
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Timer1.Stop()
End Sub
End Class
推荐阅读