Esempio n. 1
0
        private async void Clean()
        {
            if (_cameraPreviewImageSource != null)
            {
                await _cameraPreviewImageSource.StopPreviewAsync();

                _cameraPreviewImageSource.PreviewFrameAvailable -= OnPreviewFrameAvailable;
            }

            if (_timer != null)
            {
                _timer.Stop();
            }
        }
 public async Task PausePreviewAsync()
 {
     if (_initialized)
     {
         await _cameraPreviewImageSource.StopPreviewAsync();
     }
 }
Esempio n. 3
0
        private async void Dispose()
        {
            if (_cameraPreviewImageSource != null)
            {
                await _cameraPreviewImageSource.StopPreviewAsync();
            }

            if (_timer != null)
            {
                _timer.Stop();
            }
        }
Esempio n. 4
0
        public override async Task StopScanning()
        {
            _Done  = true;
            _Ready = false;

            //  wait for render cycle to end
            DateTime start = DateTime.Now;

            while (_Rendering)
            {
                if (DateTime.Now.Subtract(start).TotalMilliseconds > 1000)
                {
                    break;
                }
                await Task.Delay(10);
            }

            await _Source.StopPreviewAsync();

            Cleanup();
        }
Esempio n. 5
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;
            }
        }
Esempio n. 6
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;
            }
        }
Esempio n. 7
0
        }//hide progressBar

        private async Task DisposeResourcesAsync()
        {
            HideCommandBar();
            DisposeArray();
            if (bitmapRenderer != null)
            {
                bitmapRenderer.Dispose();
            }
            bitmapRenderer = null;

            if (isPreviewing && (cameraSource != null))
            {
                await cameraSource.StopPreviewAsync();

                cameraSource.Dispose();
            }
            cameraSource = null;
            GC.Collect();
        }//dispose page resources