简体   繁体   English

C#-更流畅的绘图笔

[英]c# - Smoother drawing pen

I have a paint program made in C#/GDI+ in which I draw different shapes with interchangeable colors and pen sizes on a panel. 我有一个用C#/ GDI +制作的绘画程序,在其中我可以在面板上用可互换的颜色和笔大小绘制不同的形状。 I have got the shape-drawing methods working OK, but when it comes to using a free pen (as you would in MS Paint) I have made a method that does the job, just quite ugly (see pic in link). 我的形状绘制方法可以正常工作,但是当涉及到使用免费笔时(就像您在MS Paint中一样),我已经制定了一种可以完成这项工作的方法,非常丑陋(请参阅链接中的图片)。

if (crtanje)
            {
                debljina = float.Parse(debljina_box.Text);
                Graphics gr = Graphics.FromImage(bit);
                gr.SmoothingMode = SmoothingMode.HighQuality;
                olovka = new Pen(boja, debljina);
                gr.DrawLine(olovka, new Point(prethodnoX ?? e.X, prethodnoY ?? e.Y), new Point(e.X, e.Y));
                panel1.CreateGraphics().DrawImageUnscaled(bit, new Point(0, 0));
                prethodnoX = e.X;
                prethodnoY = e.Y;
            }

Can this code be fixed to make drawing smoother or should I take some other approach? 可以修复此代码以使绘图更平滑,还是应该采用其他方法?

the pic 图片

I suppose you could iterate through a for loop and increase it by a very small amount so that it draws points more frequently and makes the line smoother. 我想您可以遍历for循环并将其增加很少量,以便它更频繁地绘制点并使线更平滑。 You could save the current point and calculate the next one, then draw a line between them. 您可以保存当前点并计算下一个点,然后在它们之间画一条线。 That's how you could make it smoother! 这样可以使它更平滑!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM