笔或刷子可以画点吗? [英] Can a Pen or Brush paint a Point?

查看:179
本文介绍了笔或刷子可以画点吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道我可以绘制一个实心圆,并且可以使用图形来绘制许多简单和复杂的事物.但是我无法绘制一个点(而不是一个像素).

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).

我正在使用Paint程序,并且用户可以绘制精细但不能绘制点.我可以在非常接近的地方添加一个虚拟点,或者可以绘制填充的曲线,但是有时我会错过一个明显的点.

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.

那么有没有办法使用给定的画笔或笔绘制单个点?

不,我当然不是要画一个像素.我想使用颜色和宽度之类的属性.就像一条只有一个点或两次具有相同点的DrawLine.但这什么也没有.

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.

推荐答案

    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);
        }
    }

这篇关于笔或刷子可以画点吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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