首页 > 解决方案 > 将缩放的像素化图像绘制到图片框

问题描述

我有一个 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()

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

标签: vb.netimagewinformspicturebox

解决方案


您必须在图形中指定:

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)

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


推荐阅读