Draw smooth line in InkCanvas WPF with Kinect

烂漫一生 提交于 2019-12-24 02:11:14

问题


I'm trying to create simple app that tracks right wrist position and draw line (or rather path with curves) as it moves (the exact behaviour of InkCanvas control using mouse when left mouse button is pressed).

So I track position change of RightWrist and draw line this way:

public void Paint(Point startPoint, Point nextPoint, InkCanvas paintSurface)
    {
        Line line = new Line();
        if (currentPoint.X == 0 && currentPoint.Y == 0)
        {
            currentPoint = new Point();
            currentPoint = startPoint;
        }

        line.Stroke = new SolidColorBrush(currentColor);

        line.StrokeThickness = 10;

        line.X1 = currentPoint.X;
        line.Y1 = currentPoint.Y;
        line.X2 = nextPoint.X;
        line.Y2 = nextPoint.Y;

        currentPoint = nextPoint;

        paintSurface.Children.Add(line);
    }

There is no problem when I use StrokeThickness=1. In case of bigger stroke the line on curves isn't smooth (rather build with small parts), while I would like to achieve the same result as drawing on InkCanvas with mouse and its drawing attribute set to this:

<InkCanvas.DefaultDrawingAttributes>
                <DrawingAttributes x:Name="attribute" Width="10" Height="10" Color="Green"  />
            </InkCanvas.DefaultDrawingAttributes>

The result of drawing with mouse is smooth "line".


回答1:


Three missing lines resolved my problem:

line.StrokeDashCap = PenLineCap.Round; 
line.StrokeStartLineCap = PenLineCap.Round; 
line.StrokeEndLineCap = PenLineCap.Round; 



回答2:


I know you answered your own question, I just wanted to say that you can increase the "smoothness" of Kinect's joint tracking by customizing the TransformSmoothParameters. A good tutorial for this can be found on msdn.



来源:https://stackoverflow.com/questions/21504627/draw-smooth-line-in-inkcanvas-wpf-with-kinect

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