// Event Handler for ColorFrameReady events // (A new frame of ColorStream data is available) private void KinectColorFrameReady(object sender, ColorImageFrameReadyEventArgs e) { // Get the current ColorImageFrame using (ColorImageFrame colorFrame = e.OpenColorImageFrame()) { if (colorFrame != null) { try { // Get the pixel data from the ColorImageFrame colorFrame.CopyPixelDataTo(this.colorStreamData); // Write the pixel data to the colorBitmap image colorBitmap.WritePixels(new Int32Rect(0, 0, colorFrame.Width, colorFrame.Height), colorStreamData, colorFrame.Width * colorFrame.BytesPerPixel, 0); // Dispatch the ColorDataChange event ColorDataChangeEventArgs c = new ColorDataChangeEventArgs(colorStreamData); ColorDataChange(c); } catch (NullReferenceException ex) { Console.WriteLine(ex.TargetSite + " - " + ex.Message); } } } }
protected virtual void ColorDataChange(ColorDataChangeEventArgs e) { if (ColorDataChanged != null) { ColorDataChanged(this, e); } }