使用Kinect在InkCanvas WPF中绘制平滑线 [英] Draw smooth line in InkCanvas WPF with Kinect

查看:191
本文介绍了使用Kinect在InkCanvas WPF中绘制平滑线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个简单的应用程序,该应用程序可以跟踪右手腕的位置并在其移动时绘制线条(或带有曲线的路径)(按下鼠标左键时使用鼠标操作InkCanvas控件的确切行为).

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

所以我跟踪RightWrist的位置变化并以此方式画线:

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

当我使用StrokeThickness = 1时没有问题.如果笔划较大,则曲线上的线将不平滑(而是使用较小的零件进行构建),而我希望获得与使用鼠标在InkCanvas上进行绘制以及将其drawing属性设置为以下效果相同的结果:

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

推荐答案

缺少三行内容解决了我的问题:

Three missing lines resolved my problem:

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

这篇关于使用Kinect在InkCanvas WPF中绘制平滑线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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