Esempio n. 1
0
        private async void InitializeMediaCapture()
        {
            _capturedSequence = new List <IRandomAccessStream>();

            _mediaCapture = new MediaCapture();

            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var backCamera = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource   = PhotoCaptureSource.Auto,
                AudioDeviceId        = string.Empty,
                VideoDeviceId        = backCamera.Id
            });

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

            var format = ImageEncodingProperties.CreateJpeg();

            format.Width  = 640;
            format.Height = 480;

            _lowLagPhotoSequenceCapture = await _mediaCapture.PrepareLowLagPhotoSequenceCaptureAsync(format);

            _lowLagPhotoSequenceCapture.PhotoCaptured += OnPhotoCaptured;
        }
        private async void btnStartStopPhotoSequence_Click(Object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            try
            {
                if (btnStartStopPhotoSequence.Content.ToString() == "Prepare PhotoSequence")
                {
                    if (!m_capture.VideoDeviceController.LowLagPhotoSequence.Supported)
                    {
                        rootPage.NotifyUser("Photo-sequence is not supported", NotifyType.ErrorMessage);
                    }
                    else
                    {
                        if (m_capture.VideoDeviceController.LowLagPhotoSequence.MaxPastPhotos < m_pastFrame)
                        {
                            m_pastFrame = m_capture.VideoDeviceController.LowLagPhotoSequence.MaxPastPhotos;
                            rootPage.NotifyUser("pastFrame number is past limit, reset passFrame number", NotifyType.ErrorMessage);
                        }

                        btnStartStopPhotoSequence.IsEnabled = false;

                        m_capture.VideoDeviceController.LowLagPhotoSequence.ThumbnailEnabled     = true;
                        m_capture.VideoDeviceController.LowLagPhotoSequence.DesiredThumbnailSize = 300;

                        m_capture.VideoDeviceController.LowLagPhotoSequence.PhotosPerSecondLimit = 4;
                        m_capture.VideoDeviceController.LowLagPhotoSequence.PastPhotoLimit       = m_pastFrame;

                        LowLagPhotoSequenceCapture photoCapture = await m_capture.PrepareLowLagPhotoSequenceCaptureAsync(ImageEncodingProperties.CreateJpeg());

                        photoCapture.PhotoCaptured += new Windows.Foundation.TypedEventHandler <LowLagPhotoSequenceCapture, PhotoCapturedEventArgs>(this.photoCapturedEventHandler);

                        m_photoSequenceCapture = photoCapture;

                        btnStartStopPhotoSequence.Content   = "Take PhotoSequence";
                        btnStartStopPhotoSequence.IsEnabled = true;
                        m_bPhotoSequence = true;
                    }
                }
                else if (btnStartStopPhotoSequence.Content.ToString() == "Take PhotoSequence")
                {
                    btnSaveToFile.IsEnabled = false;
                    m_frameNum      = 0;
                    m_ThumbnailNum  = 0;
                    m_selectedIndex = -1;
                    m_highLighted   = false;
                    Clear();

                    btnStartStopPhotoSequence.IsEnabled = false;
                    await m_photoSequenceCapture.StartAsync();
                }
                else
                {
                    rootPage.NotifyUser("Bad photo-sequence state", NotifyType.ErrorMessage);
                }
            }
            catch (Exception exception)
            {
                ShowExceptionMessage(exception);
            }
        }
Esempio n. 3
0
        private void CaptureHandler2(
            LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            CapturedFrame frame = args.Frame;

            // var is IAsyncOperation<TResult>
            var result = frame.FlushAsync();
        }
Esempio n. 4
0
        async private void CaptureHandler1(
            LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            CapturedFrame frame = args.Frame;

            // var is bool
            var result = await frame.FlushAsync();
        }
        private async void photoCapturedEventHandler(LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async() =>
            {
                try
                {
                    if (m_frameNum == (m_pastFrame + m_futureFrame))
                    {
                        btnStartStopPhotoSequence.IsEnabled = false;

                        await m_photoSequenceCapture.StopAsync();

                        btnStartStopPhotoSequence.IsEnabled = true;
                        btnSaveToFile.IsEnabled             = true;
                        ThumbnailGrid.SelectedIndex         = m_selectedIndex;
                    }
                    else if (m_frameNum < (m_pastFrame + m_futureFrame))
                    {
                        var bitmap = new BitmapImage();

                        m_framePtr[m_frameNum] = args.Frame;

                        bitmap.SetSource(args.Thumbnail);

                        var image    = new Image();
                        image.Source = bitmap;

                        image.Width  = 160;
                        image.Height = 120;

                        var ThumbnailItem     = new Windows.UI.Xaml.Controls.GridViewItem();
                        ThumbnailItem.Content = image;
                        ThumbnailGrid.Items.Add(ThumbnailItem);

                        if ((!m_highLighted) && (args.CaptureTimeOffset.Ticks > 0))
                        {
                            //first picture with timeSpam > 0 get highlighted
                            m_highLighted = true;

                            ThumbnailItem.BorderThickness = new Thickness(1);
                            ThumbnailItem.BorderBrush     = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
                            m_selectedIndex = (int)m_ThumbnailNum;
                        }
                        m_ThumbnailNum++;
                    }
                    m_frameNum++;
                }
                catch (Exception ex)
                {
                    ShowExceptionMessage(ex);
                }
            });
        }
Esempio n. 6
0
 public void OnPhotoCaptured(LowLagPhotoSequenceCapture s, PhotoCapturedEventArgs e)
 {
     if (_fileIndex < AMOUNT_OF_FRAMES_IN_SEQUENCE)
     {
         if (_saveTask == null)
         {
             _saveTask = Save(e.Frame, _fileIndex++);
         }
         else
         {
             _saveTask = _saveTask.ContinueWith(t => Save(e.Frame, _fileIndex++));
         }
     }
     else
     {
         StopSequenceCapture();
     }
 }
Esempio n. 7
0
        private async void photoCapturedEventHandler(LowLagPhotoSequenceCapture senders, PhotoCapturedEventArgs args)
        {
            await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, async () =>
            {

                try
                {
                    if (m_frameNum == (m_pastFrame + m_futureFrame))
                    {
                        btnStartStopPhotoSequence.IsEnabled = false;

                        await m_photoSequenceCapture.StopAsync();

                        btnStartStopPhotoSequence.IsEnabled = true;
                        btnSaveToFile.IsEnabled = true;
                        ThumbnailGrid.SelectedIndex = m_selectedIndex;
                    }
                    else if (m_frameNum < (m_pastFrame + m_futureFrame))
                    {
                        var bitmap = new BitmapImage();

                        m_framePtr[m_frameNum] = args.Frame;
               
                        bitmap.SetSource(args.Thumbnail);

                        var image = new Image();
                        image.Source = bitmap;

                        image.Width = 160;
                        image.Height = 120;

                        var ThumbnailItem = new Windows.UI.Xaml.Controls.GridViewItem();
                        ThumbnailItem.Content = image;
                        ThumbnailGrid.Items.Add(ThumbnailItem);

                        if ((!m_highLighted) && (args.CaptureTimeOffset.Ticks > 0))
                        {
                            //first picture with timeSpam > 0 get highlighted 
                            m_highLighted = true;

                            ThumbnailItem.BorderThickness = new Thickness(1);
                            ThumbnailItem.BorderBrush = new Windows.UI.Xaml.Media.SolidColorBrush(Windows.UI.Colors.Red);
                            m_selectedIndex = (int)m_ThumbnailNum;
                        }
                        m_ThumbnailNum++;
                    }
                    m_frameNum++;
                }
                catch (Exception ex)
                {
                    ShowExceptionMessage(ex);
                }
            });

        }
        private async void InitializeMediaCapture()
        {
            _capturedSequence = new List<IRandomAccessStream>();

            _mediaCapture = new MediaCapture();

            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            var backCamera = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);

            await _mediaCapture.InitializeAsync(new MediaCaptureInitializationSettings
            {
                StreamingCaptureMode = StreamingCaptureMode.Video,
                PhotoCaptureSource = PhotoCaptureSource.Auto,
                AudioDeviceId = string.Empty,
                VideoDeviceId = backCamera.Id
            });

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

            var format = ImageEncodingProperties.CreateJpeg();
            format.Width = 640;
            format.Height = 480;

            _lowLagPhotoSequenceCapture = await _mediaCapture.PrepareLowLagPhotoSequenceCaptureAsync(format);            
            _lowLagPhotoSequenceCapture.PhotoCaptured += OnPhotoCaptured;
        }
 public void OnPhotoCaptured(LowLagPhotoSequenceCapture s, PhotoCapturedEventArgs e)
 {
     if (_fileIndex < AMOUNT_OF_FRAMES_IN_SEQUENCE)
     {
         if (_saveTask == null)
         {
             _saveTask = Save(e.Frame, _fileIndex++);
         }
         else
         {
             _saveTask = _saveTask.ContinueWith(t => Save(e.Frame, _fileIndex++));
         }
     }
     else
     {
         StopSequenceCapture();
     }
 }
 public LowLagPhotoSequenceCaptureEvents(LowLagPhotoSequenceCapture This)
 {
     this.This = This;
 }