使用VB.NET实现Draw_AllChip绘制完整拼图效果

在本章节中,我们将使用Draw_AllChip()方法实现所有拼块的绘制。本方法通过缩放目标图案并调用拼块类Cchip.DrawChip()的绘制方法,以完整显示出640x480的目标图案。以下是Draw_AllChip()方法的实现细节:

Private Sub Draw_AllChip()
    '画出所有拼块及目标图案
    Dim bmp As New Bitmap(Me.Width, Me.Height)
    Me.BackgroundImage = bmp
    Dim g As Graphics = Graphics.FromImage(bmp)
    g.Clear(Me.BackColor)
    Dim r As String = n.ToString() & ".jpg"
    Dim s As Bitmap = DirectCast(Image.FromFile(r), Bitmap)
    g.DrawImage(s, New Rectangle(450, 10, 320, 240), New Rectangle(0, 0, 640, 480), GraphicsUnit.Pixel) '在(450,10)处显示320*240图案
    For i As Integer = 0 To CHIP_COUNT - 1
        m_chipList(i).DrawChip(g)
    Next
End Sub

Draw_AllChip()方法中,首先创建一个新的Bitmap对象,并设置为窗口背景。然后从图像文件加载目标图案,显示在指定位置,并以缩小尺寸(320x240)绘制。接下来,使用循环遍历m_chipList数组,调用每个拼块的DrawChip()方法,实现完整的拼图效果。

ppt 文件大小:1.31MB