初学者Kinect编程 - "' args &'在目前的背景下不存在#34;?

时间:2015-01-21 20:01:07

标签: c# xaml visual-studio-2013 kinect

好的,所以我开始编写一个应用程序,遵循Microsoft的how-to-kinect系列,一切顺利,直到我写这个:

  using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
  {
  }

出于某种原因,它一直在说当前上下文中不存在args,我不知道为什么......我的完整代码是:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.UI.Xaml.Media.Imaging;
using WindowsPreview.Kinect;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace KinectApp1
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();
            this.Loaded += MainPage_Loaded;
        }
        /*Getting the Kinect Sensor*/
        KinectSensor Sensor;

        /*Getting the Infared Reader*/
        InfraredFrameReader IRReader;

        /*This is IR Data Form*/
        ushort[] IRData;
    /*Converting the Data (Buffer) */
    byte[] IRDataConverted;

    /*Writing the Bitmap Image Described in XAML*/
    WriteableBitmap IRBitmap;

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        /*Get the sensor in the loaded frame*/
        Sensor = KinectSensor.GetDefault();

        /*Get the reader from the Source on the Sensor*/
        IRReader = Sensor.InfraredFrameSource.OpenReader();

        /*Frame Description for the Infrared and see how big they are*/
        FrameDescription FD = Sensor.InfraredFrameSource.FrameDescription;

        IRData = new ushort[FD.LengthInPixels];
        IRDataConverted = new byte[FD.LengthInPixels * 4];
        IRBitmap = new WriteableBitmap(FD.Width, FD.Height);
        Image.Source = IRBitmap;

        /*Start Sensor*/
        Sensor.Open();

        /*Subscribe to the event off the Reader*/
        IRReader.FrameArrived += IRReader_FrameArrived;

    }

    void IRReader_FrameArrived(InfraredFrameReader sender, InfraredFrameArrivedEventArgs e)
    {
        using (InfraredFrame IRFrame = args.FrameReference.AcquiredFrame())
        {
            if (IRFrame != null)
            {
                IRFrame.CopyFrameDataToArray(IRData);


                for (int i = 0; i < IRData.Length; i++)
                {
                    byte intensity = (byte)(IRData[i]>>8);
                    IRDataConverted[i*4] = intensity;
                    IRDataConverted[i*4 + 1] = intensity;
                    IRDataConverted[i*4 + 2] = intensity;
                    IRDataConverted[i*4 + 3] = 255;
                }

                IRDataConverted.CopyTo(IRBitmap.PixelBuffer);
                IRBitmap.Invalidate();

            }
        }
    }
}
}

有人可以解释为什么会这样吗?我很困惑,

先谢谢。

P.S这是我关注的视频: http://www.microsoft.com/en-us/kinectforwindows/develop/how-to-videos.aspx

1 个答案:

答案 0 :(得分:1)

嗯,它已被回答,所以我不确定除了回答它还有什么可做的:

正如 Preston Guillot 在评论中所说:

  

&#34; IRReader_FrameArrived方法中的范围内没有名为args的变量。你有一个名为e的InfraredFrameArrivedEventArgs类型的参数,我猜你打算使用&#34;