使用System.Drawing.Graphics测量线宽度不稳定

时间:2018-02-06 11:56:43

标签: c# line system.drawing.graphics

我正在尝试绘制笔宽为1的直线垂直线。以下方法绘制折线图的垂直网格线。

public override void DrawGridLines(GDIGraphics graphics, Rectangle plotArea)
{
    using (Pen pen = new Pen(gridLineColor, gridLineThickness))
    {
        float x = plotArea.Right - 1;
        for (int i = 0; i < niceIntervalCount; i++)
        {
            int roundedX = Mathf.RoundToInt(x);
            graphics.DrawLine(pen, roundedX, plotArea.Top, roundedX, plotArea.Bottom - 2);
            x -= niceIntervalSpacing;
        }
    }
}

gridLineThickness设置为1.我将整数参数传递给DrawLine方法以防止子像素渲染。我还禁用了抗锯齿功能,并将graphics.PageUnit设置为GraphicsUnit.Pixel。在一种情况下,垂直线的绘制厚度为2(通常,当多行时)。

enter image description here

在其他情况下,此错误消失。

enter image description here

点击上面的图片,查看完整尺寸,不会失真。

0 个答案:

没有答案
相关问题