Пример #1
0
        private async void init()
        {
            await capture.InitializeAsync();

            captureElement.Source = capture;
            await capture.StartPreviewAsync();

            loading.Visibility = Visibility.Collapsed;

            #region Error handling
            MediaCaptureFailedEventHandler handler = (sender, e) =>
            {
                System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Run(async() =>
                {
                    await new MessageDialog("There was an error capturing the video from camera.", "Error").ShowAsync();
                });
            };

            capture.Failed += handler;
            #endregion

            #region Advanced topic; I will complete this region later
            try
            {
                // FaceTracker tracker = await FaceTracker.CreateAsync();
                // await tracker.ProcessNextFrameAsync(await capture.GetPreviewFrameAsync());
            } catch (Exception e)
            {
                await new MessageDialog(e.InnerException.Message, "Error").ShowAsync();
            }
            #endregion
        }
Пример #2
0
        private async void InitCapture()
        // Initialize everything about MediaCapture.
        {
            this.captureMgr = new MediaCapture();
            await this.captureMgr.InitializeAsync();

            // Use the lowest resolution in order to speed up the process.
            this.SetCaptureElementToMinResolution();

            // Start the camera preview.
            captureElement.Source = this.captureMgr;
            await this.captureMgr.StartPreviewAsync();

            // Ask the camera to auto-focus now.
            var focusControl = this.captureMgr.VideoDeviceController.FocusControl;

            //var modes = focusControl.SupportedFocusModes;
            //var settings = new FocusSettings
            //{
            //    Mode = FocusMode.Auto,
            //    //Value = 100,
            //    //AutoFocusRange = AutoFocusRange.FullRange,
            //    DisableDriverFallback = true
            //};
            //focusControl.Configure(settings);
            //await focusControl.FocusAsync();

            #region Error handling
            MediaCaptureFailedEventHandler handler = (sender, e) =>
            {
                System.Threading.Tasks.Task task = System.Threading.Tasks.Task.Run(async() =>
                {
                    await new MessageDialog("There was an error capturing the video from camera.", "Error").ShowAsync();
                });
            };

            this.captureMgr.Failed += handler;
            #endregion
        }
        private async Task<MediaCapture> InitMediaCapture(MediaCaptureInitializationSettings Settings,
                                                          MediaCaptureFailedEventHandler FailedDelegate, 
                                                          RecordLimitationExceededEventHandler LimitationDelegate)
        {
            if (Settings == null)
            {
                return null;
            }
            MediaCapture capture = new MediaCapture();
            await capture.InitializeAsync(Settings);

            capture.Failed += FailedDelegate;
            capture.RecordLimitationExceeded += LimitationDelegate;

            return capture;
        }