async Task CameraInitializedAsync() { if (this.mediaCapture != null) { this.PreviewControl.Source = mediaCapture; displayRequest.RequestActive(); previewProperties = mediaCapture.VideoDeviceController.GetMediaStreamProperties(MediaStreamType.VideoPreview) as VideoEncodingProperties; await mediaCapture.StartPreviewAsync(); int w = (int)previewProperties.Width, h = (int)previewProperties.Height; var buf = new byte[w * h * 3]; reader = new BarcodeReader(); await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { if (this.mediaCapture != null) { _cameraState = CameraLoadedState.Loaded; if (_scanStarted) { StartScanner(); } } }); } }
public async Task LoadAsync() { _cameraState = CameraLoadedState.Initializing; mediaCapture = new MediaCapture(); await mediaCapture.InitializeAsync(); DisplayInformation.AutoRotationPreferences = DisplayOrientations.Landscape; mediaCapture.VideoDeviceController.FocusControl.Configure(new Windows.Media.Devices.FocusSettings { Mode = Windows.Media.Devices.FocusMode.Auto }); await CameraInitializedAsync(); if (this.timer == null) { this.timer = new DispatcherTimer(); this.timer.Interval = TimeSpan.FromMilliseconds(100); this.timer.Tick += Timer_Tick; } }