简体   繁体   English

C#UWP画布折线图绘制结果怪异

[英]C# UWP Canvas Polyline drawing weird results

I have a canvas (not InkCanvas!) and I can draw on it. 我有一个画布(不是InkCanvas!),我可以在上面绘画。 The drawing is done by the PointerMoved event, so everytime the pointer is moved I take the current position of the pointer and add it to a polyline point collection. 绘制是通过PointerMoved事件完成的,因此每次移动指针时,我都会获取指针的当前位置并将其添加到折线点集合中。 So far so good. 到现在为止还挺好。 But whenever I move my pointer very small distances the drawn line is really strange like shown below. 但是,每当我将指针移动到很小的距离时,绘制的线就会很奇怪,如下所示。

在此处输入图片说明

(the last horizontal line is not part of the bug, it's because I automatically close the polyline to a polygon) (最后一条水平线不是错误的一部分,这是因为我自动将折线关闭为多边形)

This is my code snipped: 这是我的代码片段:

private void AddPointToPolyline(Polyline pl, object sender, PointerRoutedEventArgs e)
    {
        if (e.Pointer.PointerDeviceType != PointerDeviceType.Touch)
        {
            PointerPoint pt = GetCurrentPointerPosition(sender, e);
            if (pl != null && pt != null && pl.Points.Count > 0 && pl.Points.Any())
            {
                pl.Points.Add(pt.RawPosition);
            }
        }
    }

Like I said above, this method is called everytime the pointer is moved. 就像我上面说的,每次移动指针时都会调用此方法。

I tried to implement a method that checks if two points are too close and if so discards the new point instead of putting it into the polyline. 我试图实现一种方法,该方法检查两个点是否太近,如果太近,则丢弃新点,而不是将其放入折线。 But after that the bug still occured and drawing didn't feel right anymore because it wasn't as smoothy anymore. 但是之后,该错误仍然发生,并且绘图感觉不再正确,因为它不再那么平滑。

Is there any way to fix this bug without changing to a new technology (I don't want to use InkCanvas)? 有什么方法可以解决此错误而无需更改为新技术(我不想使用InkCanvas)?

Like Clemens mentioned in a comment: 就像评论中提到的Clemens:

StrokeLineJoin to a value other than (the default value) Miter 将StrokeLineJoin设置为(默认值)斜接以外的其他值

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

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