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

Draw zoomed pixelated image to picturebox

我有一张 120x120 的 png 图片。我想取一部分 (10x10) 并将其缩放 x32 并将其显示为 picturebox 像素化 .

我做了什么:

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()

图像未像素化。我能做些什么来修复它?

您必须在图形中指定:

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)

所以你不会丢失半个像素。