不希望的抗混叠上的窗口的位图绘制时 [英] Undesired anti-aliasing when drawing bitmap on a window

查看:116
本文介绍了不希望的抗混叠上的窗口的位图绘制时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的渲染图像插入System.Drawing.Bitmap,随后绘制到一个窗口,但我可以看到边缘正在抗锯齿。如何prevent呢?

I'm rendering an image into a System.Drawing.Bitmap and subsequently drawing it into a window, however I can see that the edges are being anti-aliased. How do prevent this?

一些细节。位图是像这样创建的:

Some more detail. The bitmap is created like thus:

new Bitmap (this.Width, this.Height, Imaging.PixelFormat.Format32bppArgb)

我然后设置像素要么Color.Black或Color.White。我同时使用Bitmap.SetPixel并直接写入字节使用Bitmap.LockBits位图数据的尝试。

I then set pixels to either Color.Black or Color.White. I've tried using both Bitmap.SetPixel and writing bytes directly to the bitmap data using Bitmap.LockBits.

在该位图已经准备好我画在我的Form.OnPaint覆盖:

Once the bitmap is ready I draw it in my Form.OnPaint override:

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

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

Every pixel should either black or white however I can see that pixels at the edges are grey.

推荐答案

设置InterpolationMode属性最近邻和PixelOffsetMode为None。

Set the InterpolationMode property to NearestNeighbor and PixelOffsetMode to None.

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

绘制位图缩放的就是最好的。在这种情况下,你可能想使用ClientSize.Width和Height属性初始化位图。赔率是好的,你正在做的位图太大,现在通过包括窗体的边框和标题。我无法从片段中说。

Drawing the bitmap unscaled is best. In which case you probably want to use the ClientSize.Width and Height properties to initialize the bitmap. Odds are good that you are making the bitmap too large right now by including the form's border and caption. I can't tell from the snippet.

这篇关于不希望的抗混叠上的窗口的位图绘制时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆