禁用Graphics.FillRectangle的抗锯齿?

时间:2013-11-22 08:07:04

标签: c# winforms

我正在使用Graphics绘制一个矩形:

// x and y are arbitrary integers or floats. Doesn't matter!
Graphics.FillRectangle(Brushes.Black, x, y, 5, 5);

这会产生一个带有抗锯齿边框的黑色矩形。 如何在绘制矩形时禁用抗锯齿功能?

以下不起作用:

Graphics.SmoothingMode = SmoothingMode.HighSpeed;
Graphics.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit;

1 个答案:

答案 0 :(得分:3)

您所看到的与用于在对角线上填充楼梯的“平滑”略有不同 - 而是将矩形的边缘定位在像素的假想中心。

您需要使用

Graphics.PixelOffsetMode = PixelOffsetMode.HighSpeed 

(或其他一些枚举值,取决于你想要的精确效果)