private async Task CaptureLowLagPhotoAsync()

in Tools/Cam360/MainPage.xaml.cs [691:732]


        private async Task CaptureLowLagPhotoAsync()
        {
            try
            {
                var folder = await KnownFolders.PicturesLibrary.CreateFolderAsync("Cam360", CreationCollisionOption.OpenIfExists);
                var file = await folder.CreateFileAsync("PhotoWithRecord.jpg", CreationCollisionOption.GenerateUniqueName);
                var outputStream = await file.OpenAsync(FileAccessMode.ReadWrite);
                if (_lowLagPhotoCapture != null)
                {
                    CapturedPhoto photo = await _lowLagPhotoCapture.CaptureAsync();
                    var properties = photo.Frame.BitmapProperties;
                    var softwareBitmap = photo.Frame.SoftwareBitmap;
                    if (softwareBitmap != null)
                    {
                        var encoder = await BitmapEncoder.CreateAsync(BitmapEncoder.JpegEncoderId, outputStream);
                        if (properties != null)
                        {
                            await encoder.BitmapProperties.SetPropertiesAsync(properties);
                        }

                        encoder.SetSoftwareBitmap(softwareBitmap);
                        await encoder.FlushAsync();
                    }
                    else 
                    {
                        // This is a jpeg frame
                        var decoder = await BitmapDecoder.CreateAsync(photo.Frame.CloneStream());
                        var encoder = await BitmapEncoder.CreateForTranscodingAsync(outputStream, decoder);
                        await encoder.FlushAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                string errorMessage = string.Format("Photo capture did not complete: {0}", ex.Message);
                Debug.Write(errorMessage);
                await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                {
                    await new MessageDialog(errorMessage).ShowAsync();
                });
            }
        }