/// <summary> /// Gets the current preview frame as a SoftwareBitmap, displays its properties in a TextBlock, and can optionally display the image /// in the UI and/or save it to disk as a jpg /// </summary> /// <returns></returns> private async Task GetPreviewFrameAsSoftwareBitmapAsync() { // Get information about the preview var previewProperties = _mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; // Create the video frame to request a SoftwareBitmap preview frame var videoFrame = new VideoFrame(BitmapPixelFormat.Bgra8, (int)previewProperties.Width, (int)previewProperties.Height); // Capture the preview frame using (var currentFrame = await _mediaCapture.GetPreviewFrameAsync(videoFrame)) { // Collect the resulting frame SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap; var data = Decode(previewFrame); if (data.Count > 0) { var sb = new StringBuilder(); foreach (var d in data) { DebugUtil.Log(d); sb.Append(d); } SonyQrData qrdata = null; try { qrdata = SonyQrDataParser.ParseData(sb.ToString()); } catch (FormatException ex) { DebugUtil.Log(() => "QR data parse error: " + ex.Message); } // DebugText.Text = sb.ToString(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (qrdata != null) { Frame.Navigate(typeof(EntrancePage), qrdata); } else { AppShell.Current.Toast.PushToast(new Controls.ToastContent { Text = SystemUtil.GetStringResource("QrCodeIncompatible") }); } }); } } }
private async Task FindQrCode(VideoFrame currentFrame) { if (currentFrame == null) { return; } // Collect the resulting frame SoftwareBitmap previewFrame = currentFrame.SoftwareBitmap; var data = Decode(previewFrame); if (data.Count > 0) { var sb = new StringBuilder(); foreach (var d in data) { DebugUtil.Log(d); sb.Append(d); } SonyQrData qrdata = null; try { qrdata = SonyQrDataParser.ParseData(sb.ToString()); } catch (FormatException ex) { DebugUtil.Log(() => "QR data parse error: " + ex.Message); } // DebugText.Text = sb.ToString(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (qrdata != null) { Frame.Navigate(typeof(EntrancePage), qrdata); } else { AppShell.Current.Toast.PushToast(new Controls.ToastContent { Text = SystemUtil.GetStringResource("QrCodeIncompatible") }); } }); } }