Ejemplo n.º 1
0
        private void Uninitialize()
        {
            _initialized = false;

            if (_timer != null)
            {
                _timer.Stop();
                _timer.Tick -= DispatcherTimer_Tick;
                _timer       = null;
            }

            if (_renderer != null)
            {
                _renderer.Dispose();
                _renderer = null;
            }

            if (_effect != null)
            {
                _effect.Dispose();
                _effect = null;
            }

            _filters         = null;
            _chromaKeyFilter = null;
            _rotationFilter  = null;
            _bitmap          = null;

            if (_source != null)
            {
                _source.Dispose();
                _source = null;
            }
        }
Ejemplo n.º 2
0
        private void Cleanup()
        {
            System.Diagnostics.Debug.WriteLine("Cleaning up scanner");
            try
            {
                _Ready     = false;
                _Done      = true;
                _Rendering = true;

                _Controller   = null;
                _ImagePreview = null;
                _Effects      = null;

                _Render.Dispose();
                _Render = null;
                _Image  = null;

                _Source.StopPreviewAsync();
                _Source.PreviewFrameAvailable -= OnPreviewFrameAvailable;
                _Source.Dispose();
                _Source = null;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Cleaning up scanner. {0}", ex.Message);
            }
        }
 private void Cleanup()
 {
     if (!_cleanedUp)
     {
         // Free all - NECESSARY TO CLEANUP PROPERLY !
         _cameraPreviewImageSource.PreviewFrameAvailable -= OnPreviewFrameAvailable;
         _capturing = false;
         _cameraPreviewImageSource.Dispose();
         _writeableBitmapRenderer.Dispose();
         _cleanedUp = true;
     }
 }
Ejemplo n.º 4
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;
            }
        }
Ejemplo n.º 5
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;
            }
        }
Ejemplo n.º 6
0
        private void Uninitialize()
        {
            if (_cameraPreviewImageSource != null)
            {
                _cameraPreviewImageSource.Dispose();
                _cameraPreviewImageSource = null;
            }

            if (_blendEffect != null)
            {
                _blendEffect.Dispose();
                _blendEffect = null;
            }

            if (_blendImageProvider != null)
            {
                _blendImageProvider = null;
            }
        }
        private async Task Render()
        {
            if (!_rendering && !_stop)
            {
                _rendering = true;

                // Render camera preview frame to screen
                _writeableBitmapRenderer.Source          = _cameraPreviewImageSource;
                _writeableBitmapRenderer.WriteableBitmap = _writeableBitmap;
                await _writeableBitmapRenderer.RenderAsync();

                await Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(
                    CoreDispatcherPriority.High, () =>
                {
                    _writeableBitmap.Invalidate();
                });

                // Write camera preview frame to file if capturing
                if (_capturing)
                {
                    if (_sequenceIndex < 20)
                    {
                        _jpegRenderer.Source = _cameraPreviewImageSource;
                        IBuffer jpg = await _jpegRenderer.RenderAsync();
                        await Save(jpg, _sequenceIndex ++);
                    }
                    else
                    {
                        StartStopCapture();
                    }
                }

                _rendering = false;
            }

            if (_stop)
            {
                _capturing = false;
                _cameraPreviewImageSource.Dispose();
                _writeableBitmapRenderer.Dispose();
                _jpegRenderer.Dispose();
            }
        }
Ejemplo n.º 8
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
        private void Uninitialize()
        {
            if (_cameraPreviewImageSource != null)
            {
                _cameraPreviewImageSource.Dispose();
                _cameraPreviewImageSource = null;
            }

            if (_filterEffect != null)
            {
                _filterEffect.Dispose();
                _filterEffect = null;
            }

            if (_customEffect != null)
            {
                _customEffect.Dispose();
                _customEffect = null;
            }
        }