0

我想做的是首先找到肩关节的角度,直到现在我已经设法做到了。我现在想做的是当角度在 70 到 90 之间的范围内时开始,持续 3 秒并在每秒它应该检查角度是否仍在范围内,如果它然后显示在屏幕上确定,否则在显示消息后重新启动计时器你没有完成时间限制请让他们对 C# 和 kinect 有任何帮助这方面将有助于 em 面临的问题图像的链接是:http: //i46.tinypic.com/2nu4ygw.jpg

请帮忙!!

       System.Windows.Point shoul_l = this.point_toScreen(sh_left.Position, sen);
        draw.DrawText(new FormattedText(angle.ToString("0"), new 
        System.Globalization.CultureInfo("en-us"),
          System.Windows.FlowDirection.LeftToRight,
         new Typeface("Verdana"), 16,System.Windows.Media.Brushes.OrangeRed),
         new System.Windows.Point(shoul_l.X+10, shoul_l.Y +20));

        if (timer_start == false)
        {
        if (angle > 70 && angle < 90)
        {
                timer_start = true;
                timer.Interval = 2000;
                timer.Start();
                timer.Elapsed += new ElapsedEventHandler((sender, e) =>   \    
                on_time_event(sender, e, draw,shoul_l));

        }
        }


}   
void on_time_event(object sender, ElapsedEventArgs e, DrawingContext dcrt, 

 System.Windows.Point Shoudery_lefty)
 {
     --index;
     if (index != 0)
     {
         dcrt.DrawText(new FormattedText(index.ToString(), new   
      System.Globalization.CultureInfo("en-us"),
           System.Windows.FlowDirection.LeftToRight,
          new Typeface("Verdana"), 16, System.Windows.Media.Brushes.OrangeRed),
          new System.Windows.Point(Shoudery_lefty.X+50,Shoudery_lefty.Y+50));
      //  MessageBox.Show(index.ToString());
     }
     else
     {
         timer.Stop();
     }
   }

我在这部分代码中遇到异常

      dcrt.DrawText(new FormattedText(index.ToString(), new   
      System.Globalization.CultureInfo("en-us"),
      System.Windows.FlowDirection.LeftToRight,
      new Typeface("Verdana"), 16, System.Windows.Media.Brushes.OrangeRed),
      new System.Windows.Point(Shoudery_lefty.X+50,Shoudery_lefty.Y+50));
4

1 回答 1

2

您正在尝试从Timer线程更新 UI 元素。这是不允许的。
您必须使用以下方法将 UI 更新调用编组到 UI 线程Dispatcher

dcrt.Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => 
    {
        dcrt.DrawText(new FormattedText(index.ToString(), new System.Globalization.CultureInfo("en-us"),
       System.Windows.FlowDirection.LeftToRight,
      new Typeface("Verdana"), 16, System.Windows.Media.Brushes.OrangeRed),
      new System.Windows.Point(Shoudery_lefty.X+50,Shoudery_lefty.Y+50));
    }));
于 2012-11-01T11:40:36.387 回答