コード例 #1
0
        /*   private async Task getAsyncFile(String fileString)
         * {
         *     Windows.Storage.StorageFolder storageFolder = Windows.Storage.ApplicationData.Current.LocalFolder;
         *     await storageFolder.GetFileAsync(FILE_OUTPUT_STRING);
         * }
         */
        private void Reader_MultiSourceFrameArrived(MultiSourceFrameReader sender, MultiSourceFrameArrivedEventArgs e)
        {
            MultiSourceFrame multiSourceFrame = e.FrameReference.AcquireFrame();

            // If the frame has expired by the time we process this event, return.
            if (multiSourceFrame == null)
            {
                return;
            }

            DepthFrame        depthFrame           = null;
            ColorFrame        colorFrame           = null;
            InfraredFrame     infraredFrame        = null;
            BodyIndexFrame    bodyIndexFrame       = null;
            IBuffer           depthFrameDataBuffer = null;
            IBuffer           bodyIndexFrameData   = null;
            BodyFrame         bodyFrame            = null;
            IBufferByteAccess bodyIndexByteAccess  = null;

            switch (currentDisplayFrameType)
            {
            case DisplayFrameType.Infrared:
                using (infraredFrame = multiSourceFrame.InfraredFrameReference.AcquireFrame())
                {
                    ShowInfraredFrame(infraredFrame);
                }
                break;

            case DisplayFrameType.Color:
                using (colorFrame = multiSourceFrame.ColorFrameReference.AcquireFrame())
                {
                    ShowColorFrame(colorFrame);
                }
                break;

            case DisplayFrameType.Depth:
                using (depthFrame = multiSourceFrame.DepthFrameReference.AcquireFrame())
                {
                    ShowDepthFrame(depthFrame);
                }
                break;

            case DisplayFrameType.BodyMask:
                try
                {
                    depthFrame     = multiSourceFrame.DepthFrameReference.AcquireFrame();
                    colorFrame     = multiSourceFrame.ColorFrameReference.AcquireFrame();
                    bodyIndexFrame = multiSourceFrame.BodyIndexFrameReference.AcquireFrame();
                    if ((depthFrame == null) || (colorFrame == null) || (bodyIndexFrame == null))
                    {
                        return;
                    }

                    // Access the depth frame data directly via LockImageBuffer to avoid making a copy
                    depthFrameDataBuffer = depthFrame.LockImageBuffer();
                    coordinateMapper.MapColorFrameToDepthSpaceUsingIBuffer(depthFrameDataBuffer, colorMappedToDepthPoints);
                    // Process color
                    colorFrame.CopyConvertedFrameDataToBuffer(bitmap.PixelBuffer, ColorImageFormat.Bgra);
                    // Access the body index frame data directly via LockImageBuffer to avoid making a copy
                    bodyIndexFrameData = bodyIndexFrame.LockImageBuffer();
                    ShowMappedBodyFrame(depthFrame.FrameDescription.Width, depthFrame.FrameDescription.Height, bodyIndexFrameData, bodyIndexByteAccess);
                }
                finally
                {
                    if (depthFrame != null)
                    {
                        depthFrame.Dispose();
                    }
                    if (colorFrame != null)
                    {
                        colorFrame.Dispose();
                    }
                    if (bodyIndexFrame != null)
                    {
                        bodyIndexFrame.Dispose();
                    }
                    if (depthFrameDataBuffer != null)
                    {
                        // We must force a release of the IBuffer in order to ensure that we have
                        // dropped all references to it.
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(depthFrameDataBuffer);
                    }
                    if (bodyIndexFrameData != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(bodyIndexFrameData);
                    }
                    if (bodyIndexByteAccess != null)
                    {
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(bodyIndexByteAccess);
                    }
                }
                break;

            case DisplayFrameType.BodyJoints:
                using (bodyFrame = multiSourceFrame.BodyFrameReference.AcquireFrame())
                {
                    ShowBodyJoints(bodyFrame);
                    CalculateBodyPositions(bodyFrame);
                }
                break;

            default:
                break;
            }
        }