Exemplo n.º 1
0
    private async void FrameReader_FrameArrived(MultiSourceMediaFrameReader sender, MultiSourceMediaFrameArrivedEventArgs args)
    {
        if (capturing)
        {
            capturing = false;

            using (MultiSourceMediaFrameReference muxedFrameRef = sender.TryAcquireLatestFrame())
                using (MediaFrameReference colorFrameRef = muxedFrameRef.TryGetFrameReferenceBySourceId(_colorSourceId))
                    using (MediaFrameReference depthFrameRef = muxedFrameRef.TryGetFrameReferenceBySourceId(_depthSourceId))
                    {
                        _frameReceived.Set();
                        // do something with the frames

                        VideoMediaFrame colorFrame  = colorFrameRef.VideoMediaFrame;
                        VideoMediaFrame depthFrame  = depthFrameRef.VideoMediaFrame;
                        SoftwareBitmap  colorBitmap = colorFrame?.SoftwareBitmap;
                        SoftwareBitmap  depthBitmap = depthFrame?.SoftwareBitmap;

                        StorageFolder storageFolder = ApplicationData.Current.LocalFolder;
                        StorageFile   outputFile    = await storageFolder.CreateFileAsync("image.png", CreationCollisionOption.ReplaceExisting);

                        SaveSoftwareBitmapToFile(colorBitmap, outputFile);

                        colorBitmap.Dispose();
                        depthBitmap.Dispose();
                    }
        }
    }
Exemplo n.º 2
0
 // <SnippetMultiFrameArrived>
 private void MultiFrameReader_FrameArrived(MultiSourceMediaFrameReader sender, MultiSourceMediaFrameArrivedEventArgs args)
 {
     using (MultiSourceMediaFrameReference muxedFrame =
                sender.TryAcquireLatestFrame())
         using (MediaFrameReference colorFrame =
                    muxedFrame.TryGetFrameReferenceBySourceId(_colorSourceId))
             using (MediaFrameReference depthFrame =
                        muxedFrame.TryGetFrameReferenceBySourceId(_depthSourceId))
             {
                 // Notify the listener thread that the frame has been received.
                 _frameReceived.Set();
                 _frameRenderer.ProcessFrame(depthFrame);
             }
 }