Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/308.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在窗口上绘制位图时不需要的抗锯齿_C#_.net_Windows_Graphics_Gdi+ - Fatal编程技术网

C# 在窗口上绘制位图时不需要的抗锯齿

C# 在窗口上绘制位图时不需要的抗锯齿,c#,.net,windows,graphics,gdi+,C#,.net,Windows,Graphics,Gdi+,我正在将图像渲染到System.Drawing.Bitmap中,然后将其绘制到窗口中,但是我可以看到边缘正在进行抗锯齿处理。如何预防这种情况 更多细节。位图的创建方式如下: new Bitmap (this.Width, this.Height, Imaging.PixelFormat.Format32bppArgb) 然后我将像素设置为Color.Black或Color.White。我已经尝试使用Bitmap.SetPixel和使用Bitmap.LockBits将字节直接写入位图数据 位图准

我正在将图像渲染到System.Drawing.Bitmap中,然后将其绘制到窗口中,但是我可以看到边缘正在进行抗锯齿处理。如何预防这种情况

更多细节。位图的创建方式如下:

new Bitmap (this.Width, this.Height, Imaging.PixelFormat.Format32bppArgb)
然后我将像素设置为Color.Black或Color.White。我已经尝试使用Bitmap.SetPixel和使用Bitmap.LockBits将字节直接写入位图数据

位图准备好后,我将以我的形式绘制它。OnPaint覆盖:

            pea.Graphics.DrawImage
                ( !this.bitmap
                , this.ClientRectangle
                , new Rectangle (0, 0, this.Width, this.Height)
                , GraphicsUnit.Pixel
                )

每个像素应该是黑色或白色,但我可以看到边缘的像素是灰色的。

将插值模式属性设置为NearestNeighbor,将PixelOffsetMode设置为None

pea.Graphics.InterpolationMode = InterpolationMode.NearestNeighbor;
pea.Graphics.PixelOffsetMode = PixelOffsetMode.None; // or PixelOffsetMode.Half

绘制未缩放的位图是最好的。在这种情况下,您可能希望使用ClientSize.Width和Height属性初始化位图。很有可能是因为现在包含表单的边框和标题而使位图过大。从片段中我看不出来。

我很确定大多数人都想使用半像素偏移模式。