1

我试图在 VB.NET 中重建 BitBlt 函数,它的效果还不错,但我的图像总是在目标位图的 0,0 上进行 blitted/绘制。

有人看到我的错误吗?

正如所见,我试图将源位图中的矩形 (0, 0, 50, 50) 复制到目标位图中的点 (25,25),但它没有这样做:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    ' Make a Bitmap to hold the result.
    Dim bm As New Bitmap(Me.PictureBox1.Width, Me.PictureBox1.Height)

    CopyBitmap(Me.PictureBox1.Image, bm, 25, 25, 50, 50, 0, 0)

    Me.PictureBox2.Image = bm

End Sub

Public Sub CopyBitmap(ByRef uSource As Bitmap, ByRef uTarget As Bitmap, ByVal uDestX As Integer, ByVal uDestY As Integer, ByVal uSrcWidth As Integer, ByVal uSrcHeight As Integer, ByVal uSrcX As Integer, ByVal uSrcY As Integer)

    Dim nSrc As New Rectangle
    nSrc = Rectangle.FromLTRB(uSrcX, uSrcY, uSrcX + uSrcWidth, uSrcY + uSrcHeight)

    Dim nDst As New Rectangle
    nDst = Rectangle.FromLTRB(uDestX, uDestY, uDestX + uSrcWidth, uDestY + uSrcHeight)

    Using g As Graphics = Graphics.FromImage(uTarget)
        ' Draw the specified section of the source bitmap to the new one
        g.DrawImage(uSource, nSrc, nDst, GraphicsUnit.Pixel)
    End Using

End Sub
4

1 回答 1

1

Doh,我交换了 nSrc 和 nDst。DrawImage 中的第二个参数应该是 nDst,第三个参数应该是 nSrc。

于 2013-01-17T15:23:54.703 回答