VB.NET-绘制放大的图形出血

VB.NET-绘制放大的图形出血,vb.net,Vb.net,当我在VB.NET中尝试放大图像的一部分时,源矩形似乎溢出 BMP1 = Bitmap.FromFile(Application.StartupPath & "\TST.png") Dim G As Graphics = PictureBox3.CreateGraphics G.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor G.DrawImage(BMP1, New Poi

当我在VB.NET中尝试放大图像的一部分时,源矩形似乎溢出

    BMP1 = Bitmap.FromFile(Application.StartupPath & "\TST.png")

    Dim G As Graphics = PictureBox3.CreateGraphics
    G.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    G.DrawImage(BMP1, New Point(0, 0))
    G.Dispose()

    G = PictureBox1.CreateGraphics
    G.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    G.DrawImage(BMP1, New Rectangle(0, 0, 256, 256), 
                      New Rectangle(0, 32, 32, 32), GraphicsUnit.Pixel)
    G.Dispose()

    G = PictureBox2.CreateGraphics
    G.InterpolationMode = Drawing2D.InterpolationMode.NearestNeighbor
    G.DrawImage(BMP1, New Rectangle(0, 0, 256, 256), 
                      New Rectangle(0, 32, 31, 32), GraphicsUnit.Pixel)
    G.Dispose()

VB.NET测试图像结果:


如您所见,当放大到8倍时,图像从相邻单元借用红色像素。当我尝试将源框调整1像素时,放大的图像似乎丢失了两个像素而不是一个像素

我的问题是,如何从VB6复制拉伸行为


VB6测试图像结果:



原来答案是用矩形而不是矩形调用DrawImage,然后从源矩形的X和Y值中减去一个神奇的数字0.5。这样可以完美地缩放图像

G.DrawImage(BMP1, New RectangleF(0, 0, 256, 256), 
                  New RectangleF(-0.5, 31.5, 32, 32), GraphicsUnit.Pixel)