0

因此,首先让我向您展示我想要完成的任务:

http://www.youtube.com/watch?NR=1&feature=endscreen&v=FdwZEepJxJ4

那里的家伙正在使用 kinect 绘制一条长曲线。我需要做类似的东西。我有几个想法,只是简单的代码,比如

layoutGrid.Children.Add(myLine)

这有效,但不是我想要的方式。

我在想我可以使用drawingContext来画线:

drawingContext.DrawLine(drawPen, pointprev, point1);

问题是通过使用这种绘图方法,我绘制的线条不会保留在屏幕上。就像这条线总是被重画。我如何保持我的台词?

顺便说一句,我也不明白为什么用同样的方法绘制的骨架会更新,我们不需要清除图像中的前几行?

private void WindowLoaded(object sender, RoutedEventArgs e)
        {
            // Create the drawing group we'll use for drawing
            this.drawingGroup = new DrawingGroup();

            // Create an image source that we can use in our image control
            this.imageSource = new DrawingImage(this.drawingGroup);

            // Display the drawing using our image control
            Image2.Source = this.imageSource;

            ************Some other code here*******
         }


 private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
        {
            *****************Some code to get skeleton data here********

            using (DrawingContext dc = this.drawingGroup.Open())
            {

                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {

                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {

                            this.DrawBonesAndJoints(skel, dc);                            
                        }

                    }
                }
            }           
        }


private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext)
        {
            ***********************Some code to draw skeleton***************

            Joint righthand = skeleton.Joints[JointType.HandRight];

            if (init == true)
            {
                pointprev = SkeletonPointToScreen(righthand.Position);
                init = false;
                return;
            }


            Point point1 = SkeletonPointToScreen(righthand.Position);

            Pen drawPen = this.trackedBonePen;

            drawingContext.DrawLine(drawPen, pointprev, point1);


            pointprev = point1;

        }

private Point SkeletonPointToScreen(SkeletonPoint skelpoint)
        {
            // Convert point to depth space.  
            // We are not using depth directly, but we do want the points in our 640x480 output resolution.
            DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skelpoint, DepthImageFormat.Resolution640x480Fps30);
            return new Point(depthPoint.X, depthPoint.Y);
        }


        private void DrawBone(Skeleton skeleton, DrawingContext drawingContext, JointType jointType0, JointType jointType1)
        {
            Joint joint0 = skeleton.Joints[jointType0];
            Joint joint1 = skeleton.Joints[jointType1];          

            Pen drawPen = this.trackedBonePen;   

            drawingContext.DrawLine(drawPen, this.SkeletonPointToScreen(joint0.Position),       this.SkeletonPointToScreen(joint1.Position));
        }
4

1 回答 1

0

我如何保持我的台词?

您必须使用Polyline或通过DrawGeometry将 PathGeometry或StreamGeometry 绘制到 DrawingContext。几何图形必须包含一个或多个折线段。

于 2013-04-15T17:32:36.130 回答