将缩放的像素化图像绘制到图片框

时间:2018-09-08 15:55:18

标签: vb.net image winforms picturebox

我有一个png图片120x120。我想将它的一部分(10x10)放大到32倍,并显示为picturebox pixelated

我做了什么:

bmp = New Bitmap(320, 320, PixelFormat.Format32bppArgb) 'create a bitmap x32
Dim g As Graphics = Graphics.FromImage(bmp)

'draw the part in that bitmap
g.DrawImage(My.Resources.MyImage, New Rectangle(0, 0, 320, 320), New Rectangle(50, 50, 10, 10), GraphicsUnit.Pixel)

PictureBox1.Image = bmp

g.Dispose()

图像未像素化。我该怎么解决?

1 个答案:

答案 0 :(得分:3)

您必须在图形中指定

g.InterpolationMode = InterpolationMode.NearestNeighbor

并将矩形更改为:

g.DrawImage(My.Resources.MyImage, New RectangleF(0, 0, 320, 320), New RectangleF(49.5, 49.5, 10, 10), GraphicsUnit.Pixel)

所以您不会损失半个像素。