2013-01-17 3 views
1

VB.NET에서 BitBlt 함수를 다시 작성하려고했으나 나쁘지는 않지만, 이미지는 항상 대상 비트 맵에서 0,0으로 blitted/drawn됩니다.특정 위치에 VB.NET DrawImage

내 실수를 본 사람이 있습니까?

원본 비트 맵에서 rect (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 

답변

0

도우, nSrc와 nDst를 바꿨습니다. DrawImage의 두 번째 인수는 nDst이고 세 번째 인수는 nSrc 여야합니다.