/// <summary>
        /// Initialize and start the camera preview
        /// </summary>
        public async Task InitializeAsync()
        {
            Status = "Starting camera...";

            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(string.Empty);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width  = 640.0;
            var height = (width / properties.Width) * properties.Height;
            var bitmap = new WriteableBitmap((int)width, (int)height);

            PreviewBitmap = bitmap;

            // Create a filter effect to be used with the source (no filters yet)
            _effect = new FilterEffect(_cameraPreviewImageSource);
            _writeableBitmapRenderer = new WriteableBitmapRenderer(_effect, _writeableBitmap);

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            Status = _filterList[_index].Name;

            Initialized = true;
            NextFilterCommand.RaiseCanExecuteChanged();
            PreviousFilterCommand.RaiseCanExecuteChanged();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initialize and start the camera preview
        /// </summary>
        public async Task InitializeAsync()
        {
            Status = "Starting camera...";

            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();

            DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

            String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id;

            await _cameraPreviewImageSource.InitializeAsync(backCameraId);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width  = 640.0;
            var height = (width / properties.Width) * properties.Height;
            var bitmap = new WriteableBitmap((int)width, (int)height);

            PreviewBitmap = bitmap;

            // Create a filter effect to be used with the source (no filters yet)

            _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            Status = "Initialized";

            Initialized = true;
        }
        public async Task ResumePreviewAsync()
        {
            if (_initialized)
            {
                await _cameraPreviewImageSource.InitializeAsync(string.Empty);

                await _cameraPreviewImageSource.StartPreviewAsync();
            }
        }
Exemplo n.º 4
0
        private async Task InitCamera()
        {
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);

            string deviceId = devices.FirstOrDefault(d => d.EnclosureLocation.Panel != Windows.Devices.Enumeration.Panel.Front).Id;

            _Source = new CameraPreviewImageSource();
            await _Source.InitializeAsync(deviceId);

            _Source.PreviewFrameAvailable += OnPreviewFrameAvailable;

            //  set auto focus
            _Controller = (VideoDeviceController)_Source.VideoDeviceController;
            if (_Controller.FocusControl.Supported)
            {
                try
                {
                    if (_Controller.FocusControl.WaitForFocusSupported)
                    {
                        _Controller.FocusControl.Configure(new FocusSettings {
                            Mode = FocusMode.Continuous
                        });
                    }
                    else
                    {
                        _Controller.FocusControl.Configure(new FocusSettings {
                            Mode = FocusMode.Auto
                        });
                    }
                }
                catch
                {
                    _Controller.FocusControl.Configure(new FocusSettings {
                        Mode = FocusMode.Auto
                    });
                }
            }

            if (_Controller.FlashControl.Supported)
            {
                _Controller.FlashControl.Auto = true;
            }
            if (_Controller.ExposureControl.Supported)
            {
                _Controller.ExposureControl.SetAutoAsync(true);
            }

            _Image = new WriteableBitmap((int)Window.Current.Bounds.Width, (int)Window.Current.Bounds.Height);
            //  filters
            _Effects         = new FilterEffect(_Source);
            _Effects.Filters = new IFilter[] { new GrayscaleFilter() };

            _Render = new WriteableBitmapRenderer(_Effects, _Image);
            _Ready  = true;
        }
Exemplo n.º 5
0
        private async void Init()
        {
            //Get back camera
            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);

            var backCameraId =
                devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Panel.Back).Id;

            //Start preview
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(backCameraId);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            //Setup preview
            _width  = 640.0;
            _height = _width / properties.Width * properties.Height;
            var bitmap = new WriteableBitmap((int)_width, (int)_height);

            _writeableBitmap = bitmap;

            PreviewImage.Source = _writeableBitmap;

            _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            _videoDevice = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController;

            //Set timer for auto focus
            if (_videoDevice.FocusControl.Supported)
            {
                var focusSettings = new FocusSettings
                {
                    AutoFocusRange        = AutoFocusRange.Macro,
                    Mode                  = FocusMode.Auto,
                    WaitForFocus          = false,
                    DisableDriverFallback = false
                };

                _videoDevice.FocusControl.Configure(focusSettings);

                _timer = new DispatcherTimer
                {
                    Interval = new TimeSpan(0, 0, 0, 2, 0)
                };
                _timer.Tick += TimerOnTick;
                _timer.Start();
            }

            await _videoDevice.ExposureControl.SetAutoAsync(true);

            _initialized = true;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Initialize and start the camera preview
        /// </summary>
        public async Task InitializeAsync()
        {
            if (CaptureButton.Content.ToString().Equals("Capture and Canny"))
            {
                CaptureButton.Content = "Stop";

                // Create a camera preview image source (from Imaging SDK)
                if (_cameraPreviewImageSource == null)
                {
                    _cameraPreviewImageSource = new CameraPreviewImageSource();
                    await _cameraPreviewImageSource.InitializeAsync(string.Empty);
                }

                var properties = await _cameraPreviewImageSource.StartPreviewAsync();

                // Create a preview bitmap with the correct aspect ratio
                var width  = 640.0;
                var height = (width / properties.Width) * properties.Height;
                var bitmap = new WriteableBitmap((int)width, (int)height);

                _writeableBitmap = bitmap;

                // Create a filter effect to be used with the source (e.g. used to correct rotation)
                //_effect = new FilterEffect(_cameraPreviewImageSource);
                //_effect.Filters = new IFilter[] { new RotationFilter(90.0) };
                //_writeableBitmapRenderer = new WriteableBitmapRenderer(_effect, _writeableBitmap);

                RotationEffect rotation = new RotationEffect(_cameraPreviewImageSource, 90);

                _writeableBitmapRenderer = new WriteableBitmapRenderer(rotation, _writeableBitmap);
                //_writeableBitmapRenderer.Source = new EffectList() { _cameraPreviewImageSource, rotation };
                //_writeableBitmapRenderer.WriteableBitmap = _writeableBitmap;

                ImageView.Source = _writeableBitmap;

                // Attach preview frame delegate

                _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
            }
            else
            {
                if (CaptureButton.Content.ToString().Equals("Stop"))
                {
                    await _cameraPreviewImageSource.StopPreviewAsync();

                    _cameraPreviewImageSource.Dispose();
                    _cameraPreviewImageSource = null;
                }
                CaptureButton.Content = "Capture and Canny";
                ImageView.Source      = null;
            }
        }
Exemplo n.º 7
0
      /// <summary>
      /// Initialize and start the camera preview
      /// </summary>
      public async Task InitializeAsync()
      {
         if (CaptureButton.Content.ToString().Equals("Capture and Canny"))
         {
            CaptureButton.Content = "Stop";

            // Create a camera preview image source (from Imaging SDK)
            if (_cameraPreviewImageSource == null)
            {
               _cameraPreviewImageSource = new CameraPreviewImageSource();
               await _cameraPreviewImageSource.InitializeAsync(string.Empty);
            }

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width = 640.0;
            var height = (width / properties.Width) * properties.Height;
            var bitmap = new WriteableBitmap((int)width, (int)height);

            _writeableBitmap = bitmap;

            // Create a filter effect to be used with the source (e.g. used to correct rotation)
            //_effect = new FilterEffect(_cameraPreviewImageSource);
            //_effect.Filters = new IFilter[] { new RotationFilter(90.0) };
            //_writeableBitmapRenderer = new WriteableBitmapRenderer(_effect, _writeableBitmap);

            RotationEffect rotation = new RotationEffect(_cameraPreviewImageSource, 90);

            _writeableBitmapRenderer = new WriteableBitmapRenderer(rotation, _writeableBitmap);
            //_writeableBitmapRenderer.Source = new EffectList() { _cameraPreviewImageSource, rotation };
            //_writeableBitmapRenderer.WriteableBitmap = _writeableBitmap;

            ImageView.Source = _writeableBitmap;

            // Attach preview frame delegate
            
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
         }
         else
         {
            if (CaptureButton.Content.ToString().Equals("Stop"))
            {
               await _cameraPreviewImageSource.StopPreviewAsync();
               _cameraPreviewImageSource.Dispose();
               _cameraPreviewImageSource = null;
            }
            CaptureButton.Content = "Capture and Canny";
            ImageView.Source = null;
         }
      }
Exemplo n.º 8
0
        private async void Initialize()
        {
            var cameraId = await ViewModel.GetCameraIdAsync(Windows.Devices.Enumeration.Panel.Back);

            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(cameraId.Id);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            _width  = Window.Current.Bounds.Width;
            _height = Window.Current.Bounds.Height;
            var bitmap = new WriteableBitmap((int)_width, (int)_height);

            _writeableBitmap = bitmap;

            PreviewImage.Source = _writeableBitmap;

            _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            _videoDevice = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController;

            if (_videoDevice.FocusControl.Supported)
            {
                var focusSettings = new FocusSettings
                {
                    AutoFocusRange        = AutoFocusRange.Macro,
                    Mode                  = FocusMode.Auto,
                    WaitForFocus          = false,
                    DisableDriverFallback = false
                };

                _videoDevice.FocusControl.Configure(focusSettings);

                _timer = new DispatcherTimer
                {
                    Interval = TimeSpan.FromSeconds(2)
                };
                _timer.Tick += OnTick;
                _timer.Start();
            }

            await _videoDevice.ExposureControl.SetAutoAsync(true);

            _initialized = true;
        }
Exemplo n.º 9
0
        /// <summary>
        /// Initialize and start the camera preview
        /// </summary>
        public async Task InitializeAsync()
        {
            if (CaptureButton.Content.ToString().Equals("Capture and Canny"))
            {
                LoadButton.Visibility = Visibility.Collapsed;
                CaptureButton.Content = "Stop";

                // Create a camera preview image source (from Imaging SDK)
                if (_cameraPreviewImageSource == null)
                {
                    _cameraPreviewImageSource = new CameraPreviewImageSource();
                    await _cameraPreviewImageSource.InitializeAsync(string.Empty);
                }

                var properties = await _cameraPreviewImageSource.StartPreviewAsync();

                // Create a preview bitmap with the correct aspect ratio
                var width  = 640.0;
                var height = (width / properties.Width) * properties.Height;
                var bitmap = new WriteableBitmap((int)width, (int)height);

                _writeableBitmap = bitmap;

                // Create a filter effect to be used with the source (no filters yet)
                //_effect = new FilterEffect(_cameraPreviewImageSource);
                //_writeableBitmapRenderer = new WriteableBitmapRenderer(_effect, _writeableBitmap);
                _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

                ImageView.Source = _writeableBitmap;

                // Attach preview frame delegate
                _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
            }
            else
            {
                if (CaptureButton.Content.ToString().Equals("Stop"))
                {
                    await _cameraPreviewImageSource.StopPreviewAsync();

                    _cameraPreviewImageSource.Dispose();
                    _cameraPreviewImageSource = null;
                }
                CaptureButton.Content = "Capture and Canny";
                LoadButton.Visibility = Visibility.Visible;
                ImageView.Source      = null;
            }
        }
Exemplo n.º 10
0
      /// <summary>
      /// Initialize and start the camera preview
      /// </summary>
      public async Task InitializeAsync()
      {
         if (CaptureButton.Content.ToString().Equals("Capture and Canny"))
         {
            LoadButton.Visibility = Visibility.Collapsed;
            CaptureButton.Content = "Stop";
            
            // Create a camera preview image source (from Imaging SDK)
            if (_cameraPreviewImageSource == null)
            {
               _cameraPreviewImageSource = new CameraPreviewImageSource();
               await _cameraPreviewImageSource.InitializeAsync(string.Empty);
            }

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width = 640.0;
            var height = (width/properties.Width)*properties.Height;
            var bitmap = new WriteableBitmap((int) width, (int) height);

            _writeableBitmap = bitmap;

            // Create a filter effect to be used with the source (no filters yet)
            //_effect = new FilterEffect(_cameraPreviewImageSource);
            //_writeableBitmapRenderer = new WriteableBitmapRenderer(_effect, _writeableBitmap);
            _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

            ImageView.Source = _writeableBitmap;

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
         }
         else
         {
            if (CaptureButton.Content.ToString().Equals("Stop"))
            {
               await  _cameraPreviewImageSource.StopPreviewAsync();
               _cameraPreviewImageSource.Dispose();
               _cameraPreviewImageSource = null;
            }
            CaptureButton.Content = "Capture and Canny";
            LoadButton.Visibility = Visibility.Visible;
            ImageView.Source = null;
         }
      }
Exemplo n.º 11
0
        }//find backCamera and frontCamera

        private async Task InitializePreviewAsync()
        {
            //initialize cameraSource
            cameraSource = new CameraPreviewImageSource();
            await cameraSource.InitializeAsync(currentCamera.Id);

            //supply rendering cameraSource`s frames
            var properties = await cameraSource.StartPreviewAsync();

            cameraSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
            isPreviewing = true; isPreviEwenabled = false;
            HideProgressBar();

            //crop frames smartly
            int width; int height;

            if (properties.Width < Width || properties.Height < Height)
            {
                width = (int)properties.Width; height = (int)properties.Height;
            }
            else
            {
                width = 360; height = 640;
            }

            //connect rendered bitmap with image
            currentWriteableBitmap = new WriteableBitmap(width, height);
            image.Source           = currentWriteableBitmap;

            //create rotation effecr
            int            rotationIndex   = (currentCamera == backCamera) ? 90 : 270;
            RotationFilter _rotationFilter = new RotationFilter(rotationIndex);
            var            _filters        = new List <IFilter>();

            _filters.Add(_rotationFilter);
            var _effect = new FilterEffect(cameraSource);

            _effect.Filters = _filters;

            //finally create renderer based on effect and bitmap we are going to render
            bitmapRenderer = new WriteableBitmapRenderer(_effect, currentWriteableBitmap);
        }//initialize preview resources
Exemplo n.º 12
0
        public async Task InitializeAsync()
        {
            _timeout = BarCodeManager.MaxTry;
            _sw.Restart();
            _capturing = true;
            _cleanedUp = false;
            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();

            // La sélection de la caméra arrière plante sur mon device :/
            //var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            //var backCamera = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
            //await _cameraPreviewImageSource.InitializeAsync(backCamera.Id);
            await _cameraPreviewImageSource.InitializeAsync(string.Empty);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            vdc = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController;
            if (vdc.FocusControl.Supported)
            {
                vdc.FocusControl.Configure(new FocusSettings {
                    Mode = FocusMode.Auto
                });
                focus_period = TimeSpan.FromSeconds(5);
            }

            // Create a preview bitmap with the correct aspect ratio
            _width           = 640.0;
            _height          = (_width / properties.Width) * properties.Height;
            _writeableBitmap = new WriteableBitmap((int)_width, (int)_height);

            captureElement.Source = _writeableBitmap;

            _writeableBitmapRenderer        = new WriteableBitmapRenderer();
            _writeableBitmapRenderer.Source = _cameraPreviewImageSource;

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
        }
Exemplo n.º 13
0
        private bool isRendering; // Used to prevent multiple renderers running at once

        public async Task InitializeAsync()
        {
            // Discover all the cameras
            await EnumerateCamerasAsync();
            
            // Create a camera preview image source (from Imaging SDK)
            cameraPreviewImageSource = new CameraPreviewImageSource();
            await cameraPreviewImageSource.InitializeAsync(backCamera.Id);
            var properties = await cameraPreviewImageSource.StartPreviewAsync();

            VideoDeviceController controller = (VideoDeviceController)cameraPreviewImageSource.VideoDeviceController;            

            // Create a preview bitmap with the correct aspect ratio
            var width = properties.Width;
            var height = properties.Height;
            var bitmap = new WriteableBitmap((int)width, (int)height);

            outputBitmap = bitmap;

            // Create a filter effect to be used with the source (no filters yet)
            //effect = new LensBlurEffect(cameraPreviewImageSource, new LensBlurPredefinedKernel(LensBlurPredefinedKernelShape.Circle, 50));
            effect = new FilterEffect(cameraPreviewImageSource);

            var blur = new BlurFilter();
            blur.KernelSize = 30;
            blur.BlurRegionShape = BlurRegionShape.Elliptical;
            effect.Filters = new[] { blur };

            renderer = new WriteableBitmapRenderer(effect, outputBitmap);

            Initialized = true;

            CaptureImage.Source = outputBitmap;

            // Attach preview frame delegate
            cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
        }
        public async void InitializeAsync()
        {
            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(string.Empty);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width  = 640.0;
            var height = (width / properties.Width) * properties.Height;

            _writeableBitmap = new WriteableBitmap((int)width, (int)height);

            captureElement.Source = _writeableBitmap;

            _writeableBitmapRenderer = new WriteableBitmapRenderer();
            _jpegRenderer            = new JpegRenderer();

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            _initialized = true;
        }
Exemplo n.º 15
0
        private async void Init()
        {
            //Get back camera
            var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            var backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Panel.Back).Id;

            //Start preview
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(backCameraId);
            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            //Setup preview
            _width = 640.0;
            _height = (_width / properties.Width) * properties.Height;
            var bitmap = new WriteableBitmap((int)_width, (int)_height);

            _writeableBitmap = bitmap;

            PreviewImage.Source = _writeableBitmap;

            _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            _videoDevice = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController;
            
            //Set timer for auto focus
            if (_videoDevice.FocusControl.Supported)
            {
                var focusSettings = new FocusSettings
                {
                    AutoFocusRange = AutoFocusRange.Macro,
                    Mode = FocusMode.Auto,
                    WaitForFocus = false,
                    DisableDriverFallback = false
                };

                _videoDevice.FocusControl.Configure(focusSettings);

                _timer = new DispatcherTimer
                {
                    Interval = new TimeSpan(0, 0, 0, 2, 0)
                };
                _timer.Tick += TimerOnTick;
                _timer.Start();
            }

            await _videoDevice.ExposureControl.SetAutoAsync(true);

            _initialized = true;
        }
        /// <summary>
        /// Initialize and start the camera preview
        /// </summary>
        public async Task InitializeAsync()
        {
            Status = "Starting camera...";

            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(string.Empty);
            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width = 640.0;
            var height = (width / properties.Width) * properties.Height;
            var bitmap = new WriteableBitmap((int)width, (int)height);

            PreviewBitmap = bitmap;

            // Create a filter effect to be used with the source (no filters yet)
            _effect = new FilterEffect(_cameraPreviewImageSource);
            _writeableBitmapRenderer = new WriteableBitmapRenderer(_effect, _writeableBitmap);

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            Status = _filterList[_index].Name;

            Initialized = true;
            NextFilterCommand.RaiseCanExecuteChanged();
            PreviousFilterCommand.RaiseCanExecuteChanged();
        }
        public async void InitializeAsync()
        {
            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            await _cameraPreviewImageSource.InitializeAsync(string.Empty);
            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio 
            var width = 640.0;
            var height = (width / properties.Width) * properties.Height;
            _writeableBitmap = new WriteableBitmap((int)width, (int)height);

            captureElement.Source = _writeableBitmap;

            _writeableBitmapRenderer = new WriteableBitmapRenderer();
            _jpegRenderer = new JpegRenderer();

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            _initialized = true;
        }
Exemplo n.º 18
0
        public async Task InitializeAsync()
        {
            _timeout = BarCodeManager.MaxTry;
            _sw.Restart();
            _capturing = true;
            _cleanedUp = false;
            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();

            // La sélection de la caméra arrière plante sur mon device :/
            //var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture);
            //var backCamera = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back);
            //await _cameraPreviewImageSource.InitializeAsync(backCamera.Id);
            await _cameraPreviewImageSource.InitializeAsync(string.Empty);

            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            _width = 640.0;
            _height = (_width / properties.Width) * properties.Height;
            _writeableBitmap = new WriteableBitmap((int)_width, (int)_height);

            captureElement.Source = _writeableBitmap;

            _writeableBitmapRenderer = new WriteableBitmapRenderer();
            _writeableBitmapRenderer.Source = _cameraPreviewImageSource;

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;
        }
Exemplo n.º 19
0
        /// <summary>
        /// Initialize and start the camera preview
        /// </summary>
        public async Task InitializeAsync()
        {
            Status = "Starting camera...";

            // Create a camera preview image source (from Imaging SDK)
            _cameraPreviewImageSource = new CameraPreviewImageSource();
            
            DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
            String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id;

            await _cameraPreviewImageSource.InitializeAsync(backCameraId);
            var properties = await _cameraPreviewImageSource.StartPreviewAsync();

            // Create a preview bitmap with the correct aspect ratio
            var width = 640.0;
            var height = (width / properties.Width) * properties.Height;
            var bitmap = new WriteableBitmap((int)width, (int)height);

            PreviewBitmap = bitmap;

            // Create a filter effect to be used with the source (no filters yet)
            
            _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap);

            // Attach preview frame delegate
            _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable;

            Status = "Initialized";

            Initialized = true;
            
        }
Exemplo n.º 20
0
        private async Task InitCamera()
        {
            var devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture);
            string deviceId = devices.FirstOrDefault(d => d.EnclosureLocation.Panel != Windows.Devices.Enumeration.Panel.Front).Id;

            _Source = new CameraPreviewImageSource();
            await _Source.InitializeAsync(deviceId);
            _Source.PreviewFrameAvailable += OnPreviewFrameAvailable;

            //  set auto focus
            _Controller = (VideoDeviceController)_Source.VideoDeviceController;
            if (_Controller.FocusControl.Supported)
            {
                try
                {
                    if (_Controller.FocusControl.WaitForFocusSupported)
                    {
                        _Controller.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Continuous });
                    }
                    else
                    {
                        _Controller.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Auto });
                    }
                }
                catch
                {
                    _Controller.FocusControl.Configure(new FocusSettings { Mode = FocusMode.Auto });
                }
            }

            if (_Controller.FlashControl.Supported) _Controller.FlashControl.Auto = true;
            if (_Controller.ExposureControl.Supported) _Controller.ExposureControl.SetAutoAsync(true);

            _Image = new WriteableBitmap((int)Window.Current.Bounds.Width, (int)Window.Current.Bounds.Height);
            //  filters
            _Effects = new FilterEffect(_Source);
            _Effects.Filters = new IFilter[] { new GrayscaleFilter() };

            _Render = new WriteableBitmapRenderer(_Effects, _Image);
            _Ready = true;
        }