0

可能有一个简单的答案,但我已经尝试了很多东西,除非我只是手动显示图像,否则似乎没有任何效果,但我想要的是将此子用于其他图片以及我将在稍后修复它显示这些图像。我的代码如下

Private Sub updateStandardToolbar()
    'Draws the sprites to the pictureboxes
    Dim bit As New Bitmap(gridSize, gridSize)
    Dim dest_rect As Rectangle = New Rectangle(0, 0, gridSize, gridSize)
    Dim i As Integer = 0

    ' Associate a Graphics object with the Bitmap
    Dim gr As Graphics = Graphics.FromImage(bit)

    For y As Integer = 0 To standardNum.Y
        For x As Integer = 0 To standardNum.X
            Call getSrcRect(x, y)

            'Copy that part of the image.
            gr.DrawImage(bmpStandardTile, dest_rect, src_rect, GraphicsUnit.Pixel)

            'Display the result.
            pb(i).Image = bit

            i += 1
        Next
    Next
End Sub

这段代码的问题是所有图片框(pb())都显示相同的图片,这是我图像上的最后一张。StandardNum.x 和 standardNum.y 是分别持有 3 和 1 的变量。bmpStandardTile 是我要从中复制的图像,希望 dest_rect 和 src_rect 是不言自明的 =)。任何帮助表示赞赏。

4

1 回答 1

0

哦。在查看图片框显示相同图像的原因后,我刚刚找到了自己问题的答案。这是我的代码,如果其他人有类似或相同的问题,我如何修复它。

Private Sub updateStandardToolbar()
    'Draws the sprites to the pictureboxes
    Dim bit As Bitmap
    Dim dest_rect As Rectangle = New Rectangle(0, 0, gridSize, gridSize)
    Dim i As Integer = 0

    ' Associate a Graphics object with the Bitmap
    'Dim gr As Graphics

    'For u As Integer = 0 To maxPics
    '    bit = New Bitmap(gridSize, gridSize)
    'Next

    For y As Integer = 0 To standardNum.Y
        For x As Integer = 0 To standardNum.X
            bit = New Bitmap(gridSize, gridSize)
            Dim gr As Graphics = Graphics.FromImage(bit)
            Call getSrcRect(x, y)

            'Copy that part of the image.
            gr.DrawImage(bmpStandardTile, dest_rect, src_rect, GraphicsUnit.Pixel)

            'Display the result.
            pb(i).Image = bit

            i += 1
        Next
    Next
End Sub

答案其实很简单。傻我。我忘了清除位图图像,所以它不会改变最后一个图片框使用的图像。

bit = New Bitmap(gridSize, gridSize)

无论如何从我的错误中吸取教训=)

于 2013-02-20T08:22:23.100 回答