2013-04-15 53 views
0

所以首先讓我告訴你,我要完成的任務:C#WPF多線在畫布上繪製與Kinect感應器

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

有帥哥使用Kinect的畫長曲線。我需要做出類似的事情。我只用簡單的代碼一樣

layoutGrid.Children.Add(MYLINE)幾個想法

這工作,但不是我想要的方式。

我想我可以使用的DrawingContext來繪製線條:

drawingContext.DrawLine(drawPen,pointprev,點1);

問題是,通過使用此繪圖方法我畫的線不保留在屏幕上。這就像這條線總是重繪。我如何保持線條?

順便說一句,我也不明白爲什麼通過同樣的方法繪製的骨架得到更新,我們不需要清除圖像中的前幾行?

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

回答