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 に答える