ShatteredPheonix
ShatteredPheonix

Reputation: 77

Beginner Kinect Programming - "'args' does not exsist in the current context"?

Ok so I started writing an app following the how-to-kinect series from Microsoft and everything was going well until I wrote this:

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

For some reason it keeps saying args does not exist in the current context and I have no idea why..here is my full code:

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

            }
        }
    }
}
}

Can anyone kindly explain why this has happened? I am pretty confused,

Thanks in Advance.

P.S this is the video I was following: http://www.microsoft.com/en-us/kinectforwindows/develop/how-to-videos.aspx

Upvotes: 0

Views: 193

Answers (1)

ShatteredPheonix
ShatteredPheonix

Reputation: 77

Well it's been answered so I'm not sure what else to do apart from answer it:

As Preston Guillot said in the comments:

"There is no variable named args in scope in the IRReader_FrameArrived method. You have a parameter of type InfraredFrameArrivedEventArgs named e that I'm guessing you meant to use"

Upvotes: 1

Related Questions