async private void setEffects() { var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, 640, AnalyzeBitmap); await mediaCapture.AddEffectAsync( MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties ); }
public async Task <string> ScanAsync() { using (var capture = new MediaCapture()) { await capture.InitializeAsync(); var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, 640, AnalyzeBitmap); await capture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); return(_result?.Text ?? "Failed"); } }
private async Task InitiateCameraCaptureObject(Panel deviceLocation) { try { if (_bInitializingCamera || _cameraCapture != null) return; _bInitializingCamera = true; await InitCaptureSettings(deviceLocation); _cameraCapture = new MediaCapture(); await _cameraCapture.InitializeAsync(_captureInitSettings); //Enable QR Detector if (_qrDetectionModeEnabled) { var formats = _cameraCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.Photo); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return Math.Abs(props.Height - ActualWidth) + Math.Abs(props.Width - ActualHeight); }).First(); await _cameraCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.Photo, format); var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, format.Width >= format.Height ? format.Width : format.Height, AnalyzeImage); await _cameraCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); _barcodeReader = _barcodeReader ?? new BarcodeReader { Options = new DecodingOptions { PossibleFormats = new[] { BarcodeFormat.QR_CODE, BarcodeFormat.CODE_128 }, TryHarder = true } }; } PhotoPreview.Source = _cameraCapture; await _cameraCapture.StartPreviewAsync(); _cameraCapture.Failed += CameraCaptureOnFailed; _scannerAutoFocus = await ScannerAutoFocus.StartAsync(_cameraCapture.VideoDeviceController.FocusControl); _cameraCapture.SetPreviewRotation(VideoRotation.Clockwise90Degrees); } catch (Exception ex) { WindowsPhoneUtils.Log(ex.Message); } _bInitializingCamera = false; }
private async Task InitializeCaptureAsync() { if (m_initializing || (m_capture != null)) { return; } m_initializing = true; try { var settings = new MediaCaptureInitializationSettings { VideoDeviceId = await GetBackOrDefaulCameraIdAsync(), StreamingCaptureMode = StreamingCaptureMode.Video }; var capture = new MediaCapture(); await capture.InitializeAsync(settings); // Select the capture resolution closest to screen resolution var formats = capture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return Math.Abs(props.Width - this.ActualWidth) + Math.Abs(props.Height - this.ActualHeight); }).First(); await capture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format); // Make the preview full screen var scale = Math.Min(this.ActualWidth / format.Width, this.ActualHeight / format.Height); Preview.Width = format.Width; Preview.Height = format.Height; Preview.RenderTransformOrigin = new Point(.5, .5); Preview.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; BarcodeOutline.Width = format.Width; BarcodeOutline.Height = format.Height; BarcodeOutline.RenderTransformOrigin = new Point(.5, .5); BarcodeOutline.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; // Enable QR code detection var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, 640, AnalyzeBitmap); await capture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); // Start preview m_time.Restart(); Preview.Source = capture; await capture.StartPreviewAsync(); capture.Failed += capture_Failed; m_autoFocus = await ContinuousAutoFocus.StartAsync(capture.VideoDeviceController.FocusControl); m_capture = capture; } catch (Exception e) { TextLog.Text = String.Format("Failed to start the camera: {0}", e.Message); } m_initializing = false; }
// Must be called on the UI thread private async Task InitializeCaptureAsync() { if (m_initializing || (m_capture != null)) { return; } m_initializing = true; try { var settings = new MediaCaptureInitializationSettings { VideoDeviceId = await GetBackOrDefaulCameraIdAsync(), StreamingCaptureMode = StreamingCaptureMode.Video }; var capture = new MediaCapture(); await capture.InitializeAsync(settings); // Select the capture resolution closest to screen resolution var formats = capture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return(Math.Abs(props.Width - this.ActualWidth) + Math.Abs(props.Height - this.ActualHeight)); }).First(); await capture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format); // Make the preview full screen var scale = Math.Min(this.ActualWidth / format.Width, this.ActualHeight / format.Height); Preview.Width = format.Width; Preview.Height = format.Height; Preview.RenderTransformOrigin = new Point(.5, .5); Preview.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; //BarcodeOutline.Width = format.Width; //BarcodeOutline.Height = format.Height; //BarcodeOutline.RenderTransformOrigin = new Point(.5, .5); //BarcodeOutline.RenderTransform = new ScaleTransform { ScaleX = scale, ScaleY = scale }; // Enable QR code detection var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, 640, AnalyzeBitmap); await capture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); // Start preview //m_time.Restart(); Preview.Source = capture; await capture.StartPreviewAsync(); capture.Failed += capture_Failed; m_autoFocus = await ContinuousAutoFocus.StartAsync(capture.VideoDeviceController.FocusControl); m_capture = capture; } catch (Exception e) { MessageDialog dialog = new MessageDialog(string.Format("Failed to start the camera: {0}", e.Message)); await dialog.ShowAsync(); } m_initializing = false; }
private async Task InitializeCaptureAsync() { if (isMediaCaptureInitializing || (mediaCapture != null)) { return; } isMediaCaptureInitializing = true; try { var settings = new MediaCaptureInitializationSettings { VideoDeviceId = await GetBackOrDefaulCameraIdAsync(), StreamingCaptureMode = StreamingCaptureMode.Video }; var newMediaCapture = new MediaCapture(); await newMediaCapture.InitializeAsync(settings); // Select the capture resolution closest to screen resolution var formats = newMediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return(Math.Abs(props.Width - this.ActualHeight) + Math.Abs(props.Height - this.ActualWidth)); }).First(); Debug.WriteLine("{0} x {1}", format.Width, format.Height); await newMediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format); // Disable flash control if supported if (newMediaCapture.VideoDeviceController.FlashControl.Supported) { newMediaCapture.VideoDeviceController.FlashControl.Enabled = false; } // Prepare bitmap for reports bitmapWithBarcode = new WriteableBitmap((int)format.Width, (int)format.Height); // Make the preview full screen Preview.Width = this.ActualHeight; Preview.Height = this.ActualWidth; // Enable QR code detection var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, Math.Min(format.Width, 800), AnalyzeBitmap); await newMediaCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); // Start preview Preview.Source = newMediaCapture; await newMediaCapture.StartPreviewAsync(); newMediaCapture.Failed += OnMediaCaptureFailed; autoFocus = await ContinuousAutoFocus.StartAsync(newMediaCapture.VideoDeviceController.FocusControl); mediaCapture = newMediaCapture; } catch (Exception e) { Debug.WriteLine("Failed to start the camera: {0}", e.Message); } isMediaCaptureInitializing = false; }
private async Task InitializeCaptureAsync() { if (isMediaCaptureInitializing || (mediaCapture != null)) return; isMediaCaptureInitializing = true; try { var settings = new MediaCaptureInitializationSettings { VideoDeviceId = await GetBackOrDefaulCameraIdAsync(), StreamingCaptureMode = StreamingCaptureMode.Video }; var newMediaCapture = new MediaCapture(); await newMediaCapture.InitializeAsync(settings); // Select the capture resolution closest to screen resolution var formats = newMediaCapture.VideoDeviceController.GetAvailableMediaStreamProperties(MediaStreamType.VideoPreview); var format = (VideoEncodingProperties)formats.OrderBy((item) => { var props = (VideoEncodingProperties)item; return Math.Abs(props.Width - this.ActualHeight) + Math.Abs(props.Height - this.ActualWidth); }).First(); Debug.WriteLine("{0} x {1}", format.Width, format.Height); await newMediaCapture.VideoDeviceController.SetMediaStreamPropertiesAsync(MediaStreamType.VideoPreview, format); // Disable flash control if supported if (newMediaCapture.VideoDeviceController.FlashControl.Supported) newMediaCapture.VideoDeviceController.FlashControl.Enabled = false; // Prepare bitmap for reports bitmapWithBarcode = new WriteableBitmap((int)format.Width, (int)format.Height); // Make the preview full screen Preview.Width = this.ActualHeight; Preview.Height = this.ActualWidth; // Enable QR code detection var definition = new LumiaAnalyzerDefinition(ColorMode.Yuv420Sp, Math.Min(format.Width, 800), AnalyzeBitmap); await newMediaCapture.AddEffectAsync(MediaStreamType.VideoPreview, definition.ActivatableClassId, definition.Properties); // Start preview Preview.Source = newMediaCapture; await newMediaCapture.StartPreviewAsync(); newMediaCapture.Failed += OnMediaCaptureFailed; autoFocus = await ContinuousAutoFocus.StartAsync(newMediaCapture.VideoDeviceController.FocusControl); mediaCapture = newMediaCapture; } catch (Exception e) { Debug.WriteLine("Failed to start the camera: {0}", e.Message); } isMediaCaptureInitializing = false; }