KinectWithVRServer.MainWindow.MainWindow_DepthFrameReceived C# (CSharp) Method

MainWindow_DepthFrameReceived() private method

private MainWindow_DepthFrameReceived ( object sender, DepthFrameEventArgs e ) : void
sender object
e DepthFrameEventArgs
return void
        void MainWindow_DepthFrameReceived(object sender, DepthFrameEventArgs e)
        {
            //NOTE: Even though the depth is a 16-bit grayscale format natively, the event packs it as a bgr32.  The shaders will correct this issue.
            //This trick is necessary because the image is rasterized to an 8-bit per channel format by WPF before it is passed to the shader
            //Thus, if we used a Gray16 and then shaded it, we would lose a bunch of image depth and the scaled images would look terrible.
            if (depthSource == null)
            {
                depthSource = new WriteableBitmap(e.width, e.height, 96.0, 96.0, PixelFormats.Bgr32, null);
                DepthImage.Source = depthSource;
            }
            else if (depthSource.PixelWidth != e.width || depthSource.PixelHeight != e.height)
            {
                depthSource = null;
                depthSource = new WriteableBitmap(e.width, e.height, 96.0, 96.0, PixelFormats.Bgr32, null);
                DepthImage.Source = depthSource;
            }

            depthSource.WritePixels(new Int32Rect(0, 0, e.width, e.height), e.image, e.width * (e.bytesPerPixel + e.perPixelExtra), 0);

            //Update the depth shader, if necessary (checks for necessity are done in the methods)
            CheckAndChangeDepthShader(e.kinectID);
            UpdateShaderMinMax(e.reliableMin, e.reliableMax);

            //Calculate the depth frame rate and display it
            double tempFPS = CalculateFrameRate(e.timeStamp, ref lastDepthTime, ref depthTimeIntervals);
            DepthFPSTextBlock.Text = tempFPS.ToString("F1");
        }
MainWindow