Can a Pen or Brush paint a Point?

安稳与你 提交于 2019-12-12 04:09:51

问题


I know that I can draw a filled circle and I can draw many simple and complicated things with a Graphics. But I couldn't get it to draw a single point (not a single pixel).

I'm playing with a Paint program and the user can draw fine but not plot a dot. I can add a dummy point really close or can draw a filled cirlce but sometimes I miss the obvious.

So is there a way to draw a single point with a given Brush or Pen?

And no, of course I don't mean to draw a single Pixel. I want to use the Properties like color and width. Like a DrawLine with only one Point or with the same Point twice. But that renders nothing.


回答1:


    public void DrawPoint(Graphics G, Pen pen, Point point)
    {
        // add more LineCaps as needed..
        int pw2 = (int ) Math.Max(1, pen.Width / 2);
        using(var brush = new SolidBrush(pen.Color))
        {
            if (pen.EndCap == LineCap.Square)
                G.FillRectangle(brush, point.X - pw2, point.Y - pw2, pen.Width, pen.Width);
            else
                G.FillEllipse(brush, point.X - pw2, point.Y - pw2, pen.Width, pen.Width);
        }
    }


来源:https://stackoverflow.com/questions/22763643/can-a-pen-or-brush-paint-a-point

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!