Exemplo n.º 1
0
        private async void ViewfinderCanvas_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var point  = e.GetPosition(ViewfinderCanvas);
            var bitmap = new WriteableBitmap((int)ViewfinderCanvas.ActualWidth, (int)ViewfinderCanvas.ActualHeight);

            using (var source = new CameraPreviewImageSource(App.Camera))
                using (var effect = new FilterEffect(source))
                    using (var renderer = new WriteableBitmapRenderer(effect, bitmap, OutputOption.Stretch))
                    {
                        effect.Filters = new List <IFilter>()
                        {
                            new RotationFilter(_rotationFilter.RotationAngle)
                        };

                        await renderer.RenderAsync();

                        var picked = bitmap.Pixels[((int)point.Y) * bitmap.PixelWidth + ((int)point.X)];

                        _color = new Color
                        {
                            A = 0xFF,
                            R = (byte)((picked & 0x00FF0000) >> 16),
                            G = (byte)((picked & 0x0000FF00) >> 8),
                            B = (byte)(picked & 0x000000FF)
                        };
                    }

            ColorBorder.Background = new SolidColorBrush(_color);
        }
Exemplo 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);
            }
        }
Exemplo n.º 3
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;
            }
        }
        /// <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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
0
        protected override void CloseMedia()
        {
            if (frameStream != null)
            {
                frameStream.Close();
                frameStream = null;
            }

            cameraPreviewImageSource = null;
            photoCaptureDevice       = null;
            frameBufferSize          = 0;
            frameBuffer            = null;
            videoStreamDescription = null;
        }
Exemplo n.º 11
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.º 12
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.º 13
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;
         }
      }
        private void Initialize()
        {
            // Initialize camera

            var rotation = App.Camera.SensorLocation == CameraSensorLocation.Back ?
                           App.Camera.SensorRotationInDegrees : -App.Camera.SensorRotationInDegrees;

            ViewfinderBrush.SetSource(App.Camera);
            ViewfinderBrushTransform.Rotation = rotation;

            // Setup image processing pipeline

            _source          = new CameraPreviewImageSource(App.Camera);
            _rotationFilter  = new RotationFilter(rotation);
            _chromaKeyFilter = new ChromaKeyFilter();

            _filters = new List <IFilter> {
                _rotationFilter, _chromaKeyFilter
            };

            _effect = new FilterEffect(_source)
            {
                Filters = _filters
            };

            _bitmap   = new WriteableBitmap((int)App.Camera.PreviewResolution.Width, (int)App.Camera.PreviewResolution.Height);
            _renderer = new WriteableBitmapRenderer(_effect, _bitmap, OutputOption.Stretch);

            FilteredImage.Source = _bitmap;

            _color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);

            ColorBorder.Background = new SolidColorBrush(_color);

            // Start rendering timer

            _timer = new DispatcherTimer {
                Interval = TimeSpan.FromMilliseconds(10)
            };
            _timer.Tick += DispatcherTimer_Tick;
            _timer.Start();

            _initialized = true;
        }
Exemplo n.º 15
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
Exemplo n.º 16
0
        private void Uninitialize()
        {
            if (_cameraPreviewImageSource != null)
            {
                _cameraPreviewImageSource.Dispose();
                _cameraPreviewImageSource = null;
            }

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

            if (_blendImageProvider != null)
            {
                _blendImageProvider = null;
            }
        }
Exemplo n.º 17
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
        private void Uninitialize()
        {
            if (_cameraPreviewImageSource != null)
            {
                _cameraPreviewImageSource.Dispose();
                _cameraPreviewImageSource = null;
            }

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

            if (_customEffect != null)
            {
                _customEffect.Dispose();
                _customEffect = null;
            }
        }
Exemplo n.º 19
0
        public FrameStreamSource(PhotoCaptureDevice pcd, ObservableCollection <LiveFilter> liveFilters)
        {
            this.photoCaptureDevice = pcd;
            var smallestPreview = this.photoCaptureDevice.PreviewResolution;

            this.liveFilters = liveFilters;
            if (this.liveFilters == null || this.liveFilters.Count == 0)
            {
                this.liveFilters = new ObservableCollection <LiveFilter>();
            }

            this.liveFilters.Insert(0, LiveFilter.None);
            currentFilterIndex = 0;
            ConvertFilterEnumToIFilter(this.liveFilters[currentFilterIndex]);

            cameraPreviewImageSource = new CameraPreviewImageSource(photoCaptureDevice);
            frameSize       = new Size(smallestPreview.Width / 2, smallestPreview.Height / 2);
            frameBufferSize = (int)frameSize.Width * (int)frameSize.Height * 4; // RGBA
            frameBuffer     = new byte[frameBufferSize];
            frameStream     = new MemoryStream(frameBuffer);
        }
Exemplo n.º 20
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.º 21
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.º 23
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;
        }
        private void Initialize()
        {
            var filters = new List<IFilter>();
            var nameFormat = "{0}/" + m_EffectCount + " - {1}";

            App.AssignedColorCache = new Dictionary<uint, uint>(); // Reset
            m_StreamImageSource = new CameraPreviewImageSource(m_PhotoCaptureDevice);

            switch (m_EffectIndex)
            {
                case 0:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "NoEffect");
                        // Runs at 18 FPS with NoEffect and 18-19 FPS with nothing at all, so NoEffect() costs about 0.5 FPS
                        m_CustomEffect = new NoEffect(m_StreamImageSource);
                    }
                    break;

                case 1:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in BrightnessFilter >>> +0.50");
                        filters.Add(new BrightnessFilter(0.50));
                    }
                    break;

                case 2:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom BrightnessEffect >>> +0.50");
                        m_CustomEffect = new BrightnessEffect(m_StreamImageSource, 0.50);
                    }
                    break;

                case 3:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in BrightnessFilter >>> -0.50");
                        filters.Add(new BrightnessFilter(-0.50));
                    }
                    break;

                case 4:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom BrightnessEffect >>> -0.50");
                        m_CustomEffect = new BrightnessEffect(m_StreamImageSource, -0.50);
                    }
                    break;

                case 5:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in ColorAdjustFilter >>> Red at -1.0");
                        filters.Add(new ColorAdjustFilter(-1.0, 0, 0));
                    }
                    break;

                case 6:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom ColorAdjustEffect >>> Red at -1.0");
                        m_CustomEffect = new ColorAdjustEffect(m_StreamImageSource, -1.0, 0, 0);
                    }
                    break;

                case 7:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in ColorAdjustFilter >>> Red at +1.0");
                        filters.Add(new ColorAdjustFilter(1.0, 0, 0));
                    }
                    break;

                case 8:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom ColorAdjustEffect >>> Red at +1.0");
                        m_CustomEffect = new ColorAdjustEffect(m_StreamImageSource, 1.0, 0, 0);
                    }
                    break;

                case 9:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in ColorAdjustFilter >>> Green at -1.0");
                        filters.Add(new ColorAdjustFilter(0, -1.0, 0));
                    }
                    break;

                case 10:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom ColorAdjustEffect >>> Green at -1.0");
                        m_CustomEffect = new ColorAdjustEffect(m_StreamImageSource, 0, -1.0, 0);
                    }
                    break;

                case 11:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in ColorAdjustFilter >>> Green at +1.0");
                        filters.Add(new ColorAdjustFilter(0, 1.0, 0));
                    }
                    break;

                case 12:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom ColorAdjustEffect >>> Green at +1.0");
                        m_CustomEffect = new ColorAdjustEffect(m_StreamImageSource, 0, 1.0, 0);
                    }
                    break;

                case 13:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in ColorAdjustFilter >>> Blue at -1.0");
                        filters.Add(new ColorAdjustFilter(0, 0, -1.0));
                    }
                    break;

                case 14:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom ColorAdjustEffect >>> Blue at -1.0");
                        m_CustomEffect = new ColorAdjustEffect(m_StreamImageSource, 0, 0, -1.0);
                    }
                    break;

                case 15:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in ColorAdjustFilter >>> Blue at +1.0");
                        filters.Add(new ColorAdjustFilter(0, 0, 1.0));
                    }
                    break;

                case 16:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom ColorAdjustEffect >>> Blue at +1.0");
                        m_CustomEffect = new ColorAdjustEffect(m_StreamImageSource, 0, 0, 1.0);
                    }
                    break;

                case 17:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in MirrorFilter");
                        filters.Add(new MirrorFilter());
                    }
                    break;

                case 18:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom MirrorEffect >>> Horizontal");
                        m_CustomEffect = new MirrorEffect(m_StreamImageSource, MirrorEffect.MirrorType.Horizontal);
                    }
                    break;

                case 19:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in MirrorFilter and RotateFilter");
                        filters.Add(new RotationFilter(270));
                        filters.Add(new MirrorFilter());
                        filters.Add(new RotationFilter(90));
                    }
                    break;

                case 20:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom MirrorEffect >>> Vertical");
                        m_CustomEffect = new MirrorEffect(m_StreamImageSource, MirrorEffect.MirrorType.Vertical);
                    }
                    break;

                case 21:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in GrayscaleFilter");
                        filters.Add(new GrayscaleFilter());
                    }
                    break;

                case 22:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom GrayscaleEffect");
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource);
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.2126, 0.7152, 0.0722); // Defined Algo 1 - Default
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.212671, 0.71516, 0.072169); // CIE Y Algo
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.500, 0.419, 0.081); // R-Y Algo
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.299, 0.587, 0.114); // Defined Algo 2
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.241, 0.691, 0.068, true); // Defined Algo 3
                        //Experiments:
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.3333, 0.3333, 0.3333);
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.3990, 0.3870, 0.2140);
                        m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.3126, 0.5152, 0.0722); // very close to SDK
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.2276, 0.7152, 0.0822);
                        //m_CustomEffect = new GrayscaleEffect(m_StreamImageSource, 0.2526, 0.6652, 0.0822);
                    }
                    break;

                case 23:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in GrayscaleNegativeFilter");
                        filters.Add(new GrayscaleNegativeFilter());
                    }
                    break;

                case 24:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom GrayscaleNegativeEffect");
                        m_CustomEffect = new GrayscaleNegativeEffect(m_StreamImageSource);
                    }
                    break;

                case 25:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in NegativeFilter");
                        filters.Add(new NegativeFilter());
                    }
                    break;

                case 26:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom NegativeEffect");
                        m_CustomEffect = new NegativeEffect(m_StreamImageSource);
                    }
                    break;

                case 27:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "PixelationEffect - Scale: 5");
                        m_CustomEffect = new PixelationEffect(m_StreamImageSource, 5);
                    }
                    break;

                case 28:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "PixelationEffect - Scale: 15");
                        m_CustomEffect = new PixelationEffect(m_StreamImageSource, 15);
                    }
                    break;

                case 29:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "PixelationEffect - Scale: 35");
                        m_CustomEffect = new PixelationEffect(m_StreamImageSource, 35);
                    }
                    break;

                case 30:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "PsychedelicEffect - Factor: 25 with WarpEffect.Twister - 0.50");
                        IImageProvider imageEffect = new FilterEffect(m_StreamImageSource)
                        {
                            Filters = new List<IFilter>() { new WarpFilter(WarpEffect.Twister, 0.50) }
                        };
                        m_CustomEffect = new PsychedelicEffect(imageEffect, 25);
                    }
                    break;

                case 31:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "PsychedelicEffect - Factor: 50 with WarpEffect.Twister - 0.50");
                        IImageProvider imageEffect = new FilterEffect(m_StreamImageSource)
                        {
                            Filters = new List<IFilter>() { new WarpFilter(WarpEffect.Twister, 0.50) }
                        };
                        m_CustomEffect = new PsychedelicEffect(imageEffect, 50);
                    }
                    break;

                case 32:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "SkipPixelEffect - RowSkip: 3 | ColumnSkip: 3");
                        m_CustomEffect = new SkipPixelEffect(m_StreamImageSource, 3, 3);
                    }
                    break;

                case 33:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "SkipPixelEffect - RowSkip: 8 | ColumnSkip: 8");
                        m_CustomEffect = new SkipPixelEffect(m_StreamImageSource, 8, 8);
                    }
                    break;

                case 34:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "SkipPixelEffect - RowSkip: 13 | ColumnSkip: 13");
                        m_CustomEffect = new SkipPixelEffect(m_StreamImageSource, 13, 13);
                    }
                    break;

                case 35:
                    {
                        //// Dismal performance without Cache
                        //EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "QuantizeColorEffect without Cache - 16 color");
                        //Dictionary<uint, Color> assignedColorCache = null;
                        //_customEffect = new QuantizeColorEffect(m_StreamImageSource, ref assignedColorCache,
                        //    null, QuantizeColorEffect.ColorPalette.Color16);

                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Inbuilt CartoonFilter");
                        filters.Add(new CartoonFilter());
                    }
                    break;

                case 36:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "QuantizeColorEffect with Cache - Half of Web Safe Colors");
                        m_CustomEffect = new QuantizeColorEffect(m_StreamImageSource, ref App.AssignedColorCache,
                            null, QuantizeColorEffect.ColorPalette.WebSafeHalf);
                    }
                    break;

                case 37:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "QuantizeColorEffect with Cache - Web Safe Colors");
                        m_CustomEffect = new QuantizeColorEffect(m_StreamImageSource, ref App.AssignedColorCache,
                            null, QuantizeColorEffect.ColorPalette.WebSafe);
                    }
                    break;

                case 38:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "QuantizeColorEffect with Cache - X11 Colors");
                        m_CustomEffect = new QuantizeColorEffect(m_StreamImageSource, ref App.AssignedColorCache,
                            null, QuantizeColorEffect.ColorPalette.X11);
                    }
                    break;

                case 39:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "QuantizeColorEffect with Cache - 16 Colors");
                        m_CustomEffect = new QuantizeColorEffect(m_StreamImageSource, ref App.AssignedColorCache,
                            null, QuantizeColorEffect.ColorPalette.Color16);
                    }
                    break;

                case 40:
                    {
                        List<uint> targetColors = new List<uint>();
                        targetColors.Add(0xff000000 | (0 << 16) | (0 << 8) | 0); // Black
                        targetColors.Add(0xff000000 | (0 << 16) | (0 << 8) | 128); // Low Blue (Navy)
                        targetColors.Add(0xff000000 | (0 << 16) | (128 << 8) | 0); // Low Green (Green)
                        targetColors.Add(0xff000000 | (0 << 16) | (128 << 128) | 0); // Low Cyan (Teal)
                        targetColors.Add(0xff000000 | (128 << 16) | (0 << 8) | 0); // Low Red (Maroon)
                        targetColors.Add(0xff000000 | (175 << 16) | (238 << 8) | 238); // PaleTurquoise
                        targetColors.Add(0xff000000 | (255 << 16) | (69 << 8) | 0); // OrangeRed
                        targetColors.Add(0xff000000 | (255 << 16) | (99 << 8) | 71); // Tomato
                        targetColors.Add(0xff000000 | (255 << 16) | (0 << 8) | 255); // High Magenta (Fuchsia)
                        targetColors.Add(0xff000000 | (255 << 16) | (165 << 8) | 0); // Orange
                        targetColors.Add(0xff000000 | (255 << 16) | (255 << 8) | 0); // Yellow
                        targetColors.Add(0xff000000 | (47 << 16) | (79 << 8) | 79); // DarkSlateGray
                        targetColors.Add(0xff000000 | (255 << 16) | (255 << 8) | 255); // White
                        targetColors.Add(0xff000000 | (250 << 16) | (250 << 8) | 210); // LightGoldenrodYellow
                        targetColors.Add(0xff000000 | (176 << 16) | (196 << 8) | 222); // LightSteelBlue
                        targetColors.Add(0xff000000 | (255 << 16) | (255 << 8) | 240); // Ivory
                        targetColors.Add(0xff000000 | (255 << 16) | (245 << 8) | 238); // Seashell
                        targetColors.Add(0xff000000 | (245 << 16) | (245 << 8) | 220); // Beige
                        targetColors.Add(0xff000000 | (70 << 16) | (130 << 8) | 180); // SteelBlue
                        targetColors.Add(0xff000000 | (250 << 16) | (235 << 8) | 215); // AntiqueWhite

                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "QuantizeColorEffect with Cache - Custom Colors");
                        m_CustomEffect = new QuantizeColorEffect(m_StreamImageSource, ref App.AssignedColorCache, targetColors);
                    }
                    break;

                case 41:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Built-in SepiaFilter");
                        filters.Add(new SepiaFilter());
                    }
                    break;

                case 42:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom SepiaEffect - 0.42 (default)");
                        m_CustomEffect = new SepiaEffect(m_StreamImageSource, 0.42);
                    }
                    break;

                case 43:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom SepiaEffect - 0.32");
                        m_CustomEffect = new SepiaEffect(m_StreamImageSource, 0.32);
                    }
                    break;

                case 44:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom SepiaEffect - 0.62");
                        m_CustomEffect = new SepiaEffect(m_StreamImageSource, 0.62);
                    }
                    break;

                case 45:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom CannyEdgeDetection");
                        m_CustomEffect = new CannyEdgeDetection(m_StreamImageSource);
                    }
                    break;

                case 46:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom OtsuThresholdEffect");
                        m_CustomEffect = new OtsuThresholdEffect(m_StreamImageSource);
                    }
                    break;

                case 47:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom SobelEdgeDetection");
                        m_CustomEffect = new SobelEdgeDetection(m_StreamImageSource);
                    }
                    break;

                case 48:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom BlobCounter");

                        //CannyEdgeDetection gives better performance but sobel is much faster
                        var sobelDetection = new OtsuThresholdEffect(m_StreamImageSource);

                        m_CustomEffect = new BlobCounter(sobelDetection)
                        {
                            //Draws detected objects as rectangle, for more information http://www.aforgenet.com/articles/shape_checker/
                            HasPreview = true,
                            PreviewCount = 10,
                            ObjectsOrder = NISDKExtendedEffects.Entities.ObjectsOrder.Area
                        };
                    }

                    break;

                case 49:
                    {
                        EffectName = String.Format(nameFormat, (m_EffectIndex + 1), "Custom QuadTransformation");

                        NISDKExtendedEffects.Entities.EdgePoints points = new NISDKExtendedEffects.Entities.EdgePoints()
                        {
                            TopLeft = new System.Windows.Point(120, 50),
                            TopRight = new System.Windows.Point(550, 0),
                            BottomLeft = new System.Windows.Point(100, 440),
                            BottomRight = new System.Windows.Point(450, 300)
                        };

                        //NISDKExtendedEffects.Entities.EdgePoints points = new NISDKExtendedEffects.Entities.EdgePoints()
                        //{
                        //    TopLeft = new System.Windows.Point(20, 20),
                        //    TopRight = new System.Windows.Point(150, 0),
                        //    BottomLeft = new System.Windows.Point(50, 100),
                        //    BottomRight = new System.Windows.Point(125, 125)
                        //};

                        //NISDKExtendedEffects.Entities.EdgePoints points = new NISDKExtendedEffects.Entities.EdgePoints()
                        //{
                        //    TopLeft = new System.Windows.Point(50, 25),
                        //    TopRight = new System.Windows.Point(625, 35),
                        //    BottomLeft = new System.Windows.Point(25, 475),
                        //    BottomRight = new System.Windows.Point(640, 480)
                        //};

                        var estimatedSize = points.EstimatedRectangleSize();

                        var customEffect = new QuadTransformation(m_StreamImageSource, estimatedSize, NISDKExtendedEffects.Entities.QuadDirection.QuadToRect, points);

                        var reframingFilter = new ReframingFilter(new Windows.Foundation.Rect(0, 0, estimatedSize.Width, estimatedSize.Height), 0);

                        m_FilterEffect = new FilterEffect(customEffect)
                        {
                            Filters = new IFilter[] { reframingFilter }
                        };
                    }
                    break;
            }

            if (filters.Count > 0)
            {
                m_FilterEffect = new FilterEffect(m_StreamImageSource)
                {
                    Filters = filters
                };
            }
        }
Exemplo n.º 25
0
        private void Uninitialize()
        {
            if (_cameraPreviewImageSource != null)
            {
                _cameraPreviewImageSource.Dispose();
                _cameraPreviewImageSource = null;
            }

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

            if (_blendImageProvider != null)
            {
                _blendImageProvider = null;
            }
        }
Exemplo n.º 26
0
 private void Initialize()
 {
     if (_cameraPreviewImageSource == null && _photoCaptureDevice != null)
     {
         _cameraPreviewImageSource = new CameraPreviewImageSource(_photoCaptureDevice);
     }
     
     if (_effectIndex >= 0 && _effectIndex < EffectGroup.Count && _cameraPreviewImageSource != null)
     {
         AbstractFilter filter = EffectGroup[_effectIndex];
         filter.RealtimeEffectSource = _cameraPreviewImageSource;
     }
 }
        private void Initialize()
        {
            var filters    = new List <IFilter>();
            var nameFormat = "{0}/" + _effectCount + " - {1}";

            _cameraPreviewImageSource = new CameraPreviewImageSource(_photoCaptureDevice);

            switch (_effectIndex)
            {
            case 0:
            {
                EffectName = String.Format(nameFormat, 1, AppResources.Filter_Lomo);
                filters.Add(new LomoFilter(0.5, 0.5, LomoVignetting.High, LomoStyle.Yellow));
            }
            break;

            case 1:
            {
                EffectName = String.Format(nameFormat, 2, AppResources.Filter_MagicPen);
                filters.Add(new MagicPenFilter());
            }
            break;

            case 2:
            {
                EffectName = String.Format(nameFormat, 3, AppResources.Filter_Grayscale);
                filters.Add(new GrayscaleFilter());
            }
            break;

            case 3:
            {
                EffectName = String.Format(nameFormat, 4, AppResources.Filter_Antique);
                filters.Add(new AntiqueFilter());
            }
            break;

            case 4:
            {
                EffectName = String.Format(nameFormat, 5, AppResources.Filter_Stamp);
                filters.Add(new StampFilter(4, 0.3));
            }
            break;

            case 5:
            {
                EffectName = String.Format(nameFormat, 6, AppResources.Filter_Cartoon);
                filters.Add(new CartoonFilter(false));
            }
            break;

            case 6:
            {
                EffectName = String.Format(nameFormat, 7, AppResources.Filter_Sepia);
                filters.Add(new SepiaFilter());
            }
            break;

            case 7:
            {
                EffectName = String.Format(nameFormat, 8, AppResources.Filter_Sharpness);
                filters.Add(new SharpnessFilter(7));
            }
            break;

            case 8:
            {
                EffectName = String.Format(nameFormat, 9, AppResources.Filter_AutoEnhance);
                filters.Add(new AutoEnhanceFilter());
            }
            break;

            case 9:
            {
                EffectName = String.Format(nameFormat, 10, AppResources.Filter_None);
            }
            break;

            case 10:
            {
                EffectName    = String.Format(nameFormat, 11, AppResources.Filter_Custom);
                _customEffect = new CustomEffect(_cameraPreviewImageSource);
            }
            break;
            }

            if (filters.Count > 0)
            {
                _filterEffect = new FilterEffect(_cameraPreviewImageSource)
                {
                    Filters = filters
                };
            }
        }
Exemplo n.º 28
0
        private void Initialize()
        {
            // Initialize camera

            var rotation = App.Camera.SensorLocation == CameraSensorLocation.Back ?
                App.Camera.SensorRotationInDegrees : - App.Camera.SensorRotationInDegrees;

            ViewfinderBrush.SetSource(App.Camera);
            ViewfinderBrushTransform.Rotation = rotation;

            // Setup image processing pipeline

            _source = new CameraPreviewImageSource(App.Camera);
            _rotationFilter = new RotationFilter(rotation);
            _chromaKeyFilter = new ChromaKeyFilter();

            _filters = new List<IFilter> {_rotationFilter, _chromaKeyFilter};

            _effect = new FilterEffect(_source) {Filters = _filters};

            _bitmap = new WriteableBitmap((int)App.Camera.PreviewResolution.Width, (int)App.Camera.PreviewResolution.Height);
            _renderer = new WriteableBitmapRenderer(_effect, _bitmap, OutputOption.Stretch);

            FilteredImage.Source = _bitmap;

            _color = Color.FromArgb(0xFF, 0xFF, 0xFF, 0xFF);

            ColorBorder.Background = new SolidColorBrush(_color);

            // Start rendering timer

            _timer = new DispatcherTimer { Interval = TimeSpan.FromMilliseconds(10) };
            _timer.Tick += DispatcherTimer_Tick;
            _timer.Start();

            _initialized = true;
        }
Exemplo n.º 29
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);
            }
        }
Exemplo n.º 30
0
        private void Initialize()
        {
            var filters = new List<IFilter>();
            var nameFormat = "{0}/" + _effectCount + " - {1}";

            _cameraPreviewImageSource = new CameraPreviewImageSource(_photoCaptureDevice);

            switch (_effectIndex)
            {
                case 0:
                    {
                        EffectName = String.Format(nameFormat, 1, AppResources.Filter_Lomo);
                        filters.Add(new LomoFilter(0.5, 0.5, LomoVignetting.High, LomoStyle.Yellow));
                    }
                    break;

                case 1:
                    {
                        EffectName = String.Format(nameFormat, 2, AppResources.Filter_MagicPen);
                        filters.Add(new MagicPenFilter());
                    }
                    break;

                case 2:
                    {
                        EffectName = String.Format(nameFormat, 3, AppResources.Filter_Grayscale);
                        filters.Add(new GrayscaleFilter());
                    }
                    break;

                case 3:
                    {
                        EffectName = String.Format(nameFormat, 4, AppResources.Filter_Antique);
                        filters.Add(new AntiqueFilter());
                    }
                    break;

                case 4:
                    {
                        EffectName = String.Format(nameFormat, 5, AppResources.Filter_Stamp);
                        filters.Add(new StampFilter(4, 0.3));
                    }
                    break;

                case 5:
                    {
                        EffectName = String.Format(nameFormat, 6, AppResources.Filter_Cartoon);
                        filters.Add(new CartoonFilter(false));
                    }
                    break;

                case 6:
                    {
                        EffectName = String.Format(nameFormat, 7, AppResources.Filter_Sepia);
                        filters.Add(new SepiaFilter());
                    }
                    break;

                case 7:
                    {
                        EffectName = String.Format(nameFormat, 8, AppResources.Filter_Sharpness);
                        filters.Add(new SharpnessFilter(7));
                    }
                    break;

                case 8:
                    {
                        EffectName = String.Format(nameFormat, 9, AppResources.Filter_AutoEnhance);
                        filters.Add(new AutoEnhanceFilter());
                    }
                    break;

                case 9:
                    {
                        EffectName = String.Format(nameFormat, 10, AppResources.Filter_None);
                    }
                    break;

                case 10:
                    {
                        EffectName = String.Format(nameFormat, 11, AppResources.Filter_Custom);
                        _customEffect = new CustomEffect(_cameraPreviewImageSource);
                    }
                    break;
            }

            if (filters.Count > 0)
            {
                _filterEffect = new FilterEffect(_cameraPreviewImageSource)
                {
                    Filters = filters
                };
            }
        }
Exemplo n.º 31
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.º 32
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;
            }
        }
        private void Uninitialize()
        {
            if (_cameraPreviewImageSource != null)
            {
                _cameraPreviewImageSource.Dispose();
                _cameraPreviewImageSource = null;
            }

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

            if (_customEffect != null)
            {
                _customEffect.Dispose();
                _customEffect = null;
            }
        }
Exemplo n.º 34
0
        private async void ViewfinderCanvas_Tap(object sender, System.Windows.Input.GestureEventArgs e)
        {
            var point = e.GetPosition(ViewfinderCanvas);
            var bitmap = new WriteableBitmap((int)ViewfinderCanvas.ActualWidth, (int)ViewfinderCanvas.ActualHeight);

            using (var source = new CameraPreviewImageSource(App.Camera))
            using (var effect = new FilterEffect(source))
            using (var renderer = new WriteableBitmapRenderer(effect, bitmap, OutputOption.Stretch))
            {
                effect.Filters = new List<IFilter>()
                {
                    new RotationFilter(_rotationFilter.RotationAngle)
                };

                await renderer.RenderAsync();

                var picked = bitmap.Pixels[((int)point.Y) * bitmap.PixelWidth + ((int)point.X)];

                _color = new Color
                {
                    A = 0xFF,
                    R = (byte)((picked & 0x00FF0000) >> 16),
                    G = (byte)((picked & 0x0000FF00) >> 8),
                    B = (byte)(picked & 0x000000FF)
                };
            }

            ColorBorder.Background = new SolidColorBrush(_color);
        }
        private void Uninitialize()
        {
            if (m_StreamImageSource != null)
            {
                m_StreamImageSource.Dispose();
                m_StreamImageSource = null;
            }

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

            if (m_CustomEffect != null)
            {
                m_CustomEffect.Dispose();
                m_CustomEffect = null;
            }
        }
        /// <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.º 37
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.º 38
0
        private void Initialize()
        {
            _cameraPreviewImageSource = new CameraPreviewImageSource(_photoCaptureDevice);

            if (_blendImageUri != null)
            {
                _blendImageProvider = new StreamImageSource((System.Windows.Application.GetResourceStream(_blendImageUri).Stream));
            }
            else
            {
                var colorStops = new GradientStop[]
                {
                    new GradientStop { Color = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00), Offset = 0.0 },
                    new GradientStop { Color = Color.FromArgb(0xFF, 0x00, 0xFF, 0x00), Offset = 0.7 },
                    new GradientStop { Color = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), Offset = 1.0 }
                };

                var gradient = new RadialGradient(new Point(0, 0), new EllipseRadius(1, 0), colorStops);

                var size = new Size(640, 480);

                _blendImageProvider = new GradientImageSource(size, gradient);
            }

            var nameFormat = "{0}/" + EffectCount + " - {1}";

            switch (_effectIndex)
            {
                case 0:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_None);
                    }
                    break;

                case 1:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Normal);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Normal, GlobalAlpha);
                    }
                    break;

                case 2:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Multiply);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Multiply, GlobalAlpha);
                    }
                    break;

                case 3:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Add);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Add, GlobalAlpha);
                    }
                    break;

                case 4:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Color);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Color, GlobalAlpha);
                    }
                    break;

                case 5:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Colorburn);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Colorburn, GlobalAlpha);
                    }
                    break;

                case 6:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Colordodge);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Colordodge, GlobalAlpha);
                    }
                    break;

                case 7:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Overlay);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Overlay, GlobalAlpha);
                    }
                    break;

                case 8:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Softlight);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Softlight, GlobalAlpha);
                    }
                    break;

                case 9:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Screen);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Screen, GlobalAlpha);
                    }
                    break;

                case 10:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Hardlight);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Hardlight, GlobalAlpha);
                    }
                    break;

                case 11:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Darken);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Darken, GlobalAlpha);
                    }
                    break;

                case 12:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Lighten);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Lighten, GlobalAlpha);
                    }
                    break;

                case 13:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Hue);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Hue, GlobalAlpha);
                    }
                    break;

                case 14:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Exclusion);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Exclusion, GlobalAlpha);
                    }
                    break;

                case 15:
                    {
                        EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Difference);
                        _blendEffect = new BlendEffect(_cameraPreviewImageSource,_blendImageProvider, BlendFunction.Difference, GlobalAlpha);
                    }
                    break;
            }

            if (_blendEffect != null)
            {
                _blendEffect.TargetArea = _targetArea;
                _blendEffect.TargetAreaRotation = _targetAreaRotation;                
            }
        }
        private void Initialize()
        {
            var filters = new List<IFilter>();
            var nameFormat = "{0}/" + _effectCount + " - {1}";

            _cameraPreviewImageSource = new CameraPreviewImageSource(_photoCaptureDevice);

            switch (_effectIndex)
            {
                case 0:
                    {
                        EffectName = String.Format(nameFormat, 1, AppResources.Filter_Lomo);
                        filters.Add(new LomoFilter(0.5, 0.5, LomoVignetting.High, LomoStyle.Yellow));
                    }
                    break;

                case 1:
                    {
                        EffectName = String.Format(nameFormat, 2, AppResources.Filter_MagicPen);
                        filters.Add(new MagicPenFilter());
                    }
                    break;

                case 2:
                    {
                        EffectName = String.Format(nameFormat, 3, AppResources.Filter_Grayscale);
                        filters.Add(new GrayscaleFilter());
                    }
                    break;

                case 3:
                    {
                        EffectName = String.Format(nameFormat, 4, AppResources.Filter_Antique);
                        filters.Add(new AntiqueFilter());
                    }
                    break;

                case 4:
                    {
                        EffectName = String.Format(nameFormat, 5, AppResources.Filter_Stamp);
                        filters.Add(new StampFilter(4, 0.3));
                    }
                    break;

                case 5:
                    {
                        EffectName = String.Format(nameFormat, 6, AppResources.Filter_Cartoon);
                        filters.Add(new CartoonFilter(false));
                    }
                    break;

                case 6:
                    {
                        EffectName = String.Format(nameFormat, 7, AppResources.Filter_Sepia);
                        filters.Add(new SepiaFilter());
                    }
                    break;

                case 7:
                    {
                        EffectName = String.Format(nameFormat, 8, AppResources.Filter_Sharpness);
                        filters.Add(new SharpnessFilter(7));
                    }
                    break;

                case 8:
                    {
                        EffectName = String.Format(nameFormat, 9, AppResources.Filter_AutoEnhance);
                        filters.Add(new AutoEnhanceFilter());
                    }
                    break;

                case 9:
                    {
                        EffectName = String.Format(nameFormat, 10, AppResources.Filter_None);
                    }
                    break;

                case 10:
                    {
                        EffectName = String.Format(nameFormat, 11, AppResources.Filter_Custom);
                        _customEffect = new CustomEffect(_cameraPreviewImageSource);
                    }
                    break;

                case 11:
                    {
                        EffectName = String.Format(nameFormat, 12, "Built-in BrightnessFilter >>> +0.50");
                        filters.Add(new BrightnessFilter(0.50));
                    }
                    break;

                case 12:
                    {
                        EffectName = String.Format(nameFormat, 13, "Custom BrightnessEffect >>> +0.50");
                        _customEffect = new BrightnessEffect(_cameraPreviewImageSource, 0.50);
                    }
                    break;

                case 13:
                    {
                        EffectName = String.Format(nameFormat, 14, "Built-in BrightnessFilter >>> -0.50");
                        filters.Add(new BrightnessFilter(-0.50));
                    }
                    break;

                case 14:
                    {
                        EffectName = String.Format(nameFormat, 15, "Custom BrightnessEffect >>> -0.50");
                        _customEffect = new BrightnessEffect(_cameraPreviewImageSource, -0.50);
                    }
                    break;

                case 15:
                    {
                        EffectName = String.Format(nameFormat, 16, "Built-in ColorAdjustFilter >>> Red at -1.0");
                        filters.Add(new ColorAdjustFilter(-1.0, 0, 0));
                    }
                    break;

                case 16:
                    {
                        EffectName = String.Format(nameFormat, 17, "Custom ColorAdjustEffect >>> Red at -1.0");
                        _customEffect = new ColorAdjustEffect(_cameraPreviewImageSource, -1.0, 0, 0);
                    }
                    break;

                case 17:
                    {
                        EffectName = String.Format(nameFormat, 18, "Built-in ColorAdjustFilter >>> Red at +1.0");
                        filters.Add(new ColorAdjustFilter(1.0, 0, 0));
                    }
                    break;

                case 18:
                    {
                        EffectName = String.Format(nameFormat, 19, "Custom ColorAdjustEffect >>> Red at +1.0");
                        _customEffect = new ColorAdjustEffect(_cameraPreviewImageSource, 1.0, 0, 0);
                    }
                    break;

                case 19:
                    {
                        EffectName = String.Format(nameFormat, 20, "Built-in ColorAdjustFilter >>> Green at -1.0");
                        filters.Add(new ColorAdjustFilter(0, -1.0, 0));
                    }
                    break;

                case 20:
                    {
                        EffectName = String.Format(nameFormat, 21, "Custom ColorAdjustEffect >>> Green at -1.0");
                        _customEffect = new ColorAdjustEffect(_cameraPreviewImageSource, 0, -1.0, 0);
                    }
                    break;

                case 21:
                    {
                        EffectName = String.Format(nameFormat, 22, "Built-in ColorAdjustFilter >>> Green at +1.0");
                        filters.Add(new ColorAdjustFilter(0, 1.0, 0));
                    }
                    break;

                case 22:
                    {
                        EffectName = String.Format(nameFormat, 23, "Custom ColorAdjustEffect >>> Green at +1.0");
                        _customEffect = new ColorAdjustEffect(_cameraPreviewImageSource, 0, 1.0, 0);
                    }
                    break;

                case 23:
                    {
                        EffectName = String.Format(nameFormat, 24, "Built-in ColorAdjustFilter >>> Blue at -1.0");
                        filters.Add(new ColorAdjustFilter(0, 0, -1.0));
                    }
                    break;

                case 24:
                    {
                        EffectName = String.Format(nameFormat, 25, "Custom ColorAdjustEffect >>> Blue at -1.0");
                        _customEffect = new ColorAdjustEffect(_cameraPreviewImageSource, 0, 0, -1.0);
                    }
                    break;

                case 25:
                    {
                        EffectName = String.Format(nameFormat, 26, "Built-in ColorAdjustFilter >>> Blue at +1.0");
                        filters.Add(new ColorAdjustFilter(0, 0, 1.0));
                    }
                    break;

                case 26:
                    {
                        EffectName = String.Format(nameFormat, 27, "Custom ColorAdjustEffect >>> Blue at +1.0");
                        _customEffect = new ColorAdjustEffect(_cameraPreviewImageSource, 0, 0, 1.0);
                    }
                    break;

                case 27:
                    {
                        EffectName = String.Format(nameFormat, 28, "Built-in MirrorFilter");
                        filters.Add(new MirrorFilter());
                    }
                    break;

                case 28:
                    {
                        EffectName = String.Format(nameFormat, 29, "Custom MirrorEffect >>> Horizontal");
                        _customEffect = new MirrorEffect(_cameraPreviewImageSource, MirrorEffect.MirrorType.Horizontal);
                    }
                    break;

                case 29:
                    {
                        EffectName = String.Format(nameFormat, 30, "Built-in MirrorFilter and RotateFilter");
                        filters.Add(new RotationFilter(270)); 
                        filters.Add(new MirrorFilter());
                        filters.Add(new RotationFilter(90));
                        
                    }
                    break;

                case 30:
                    {
                        EffectName = String.Format(nameFormat, 31, "Custom MirrorEffect >>> Vertical");
                        _customEffect = new MirrorEffect(_cameraPreviewImageSource, MirrorEffect.MirrorType.Vertical);
                    }
                    break;
            }

            if (filters.Count > 0)
            {
                _filterEffect = new FilterEffect(_cameraPreviewImageSource)
                {
                    Filters = filters
                };
            }
        }
Exemplo n.º 40
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.º 41
0
        private void Initialize()
        {
            _cameraPreviewImageSource = new CameraPreviewImageSource(_photoCaptureDevice);

            if (_blendImageUri != null)
            {
                _blendImageProvider = new StreamImageSource((System.Windows.Application.GetResourceStream(_blendImageUri).Stream));
            }
            else
            {
                var colorStops = new GradientStop[]
                {
                    new GradientStop {
                        Color = Color.FromArgb(0xFF, 0xFF, 0x00, 0x00), Offset = 0.0
                    },
                    new GradientStop {
                        Color = Color.FromArgb(0xFF, 0x00, 0xFF, 0x00), Offset = 0.7
                    },
                    new GradientStop {
                        Color = Color.FromArgb(0xFF, 0x00, 0x00, 0xFF), Offset = 1.0
                    }
                };

                var gradient = new RadialGradient(new Point(0, 0), new EllipseRadius(1, 0), colorStops);

                var size = new Size(640, 480);

                _blendImageProvider = new GradientImageSource(size, gradient);
            }

            var nameFormat = "{0}/" + EffectCount + " - {1}";

            switch (_effectIndex)
            {
            case 0:
            {
                EffectName = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_None);
            }
            break;

            case 1:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Normal);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Normal, GlobalAlpha);
            }
            break;

            case 2:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Multiply);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Multiply, GlobalAlpha);
            }
            break;

            case 3:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Add);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Add, GlobalAlpha);
            }
            break;

            case 4:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Color);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Color, GlobalAlpha);
            }
            break;

            case 5:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Colorburn);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Colorburn, GlobalAlpha);
            }
            break;

            case 6:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Colordodge);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Colordodge, GlobalAlpha);
            }
            break;

            case 7:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Overlay);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Overlay, GlobalAlpha);
            }
            break;

            case 8:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Softlight);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Softlight, GlobalAlpha);
            }
            break;

            case 9:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Screen);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Screen, GlobalAlpha);
            }
            break;

            case 10:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Hardlight);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Hardlight, GlobalAlpha);
            }
            break;

            case 11:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Darken);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Darken, GlobalAlpha);
            }
            break;

            case 12:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Lighten);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Lighten, GlobalAlpha);
            }
            break;

            case 13:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Hue);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Hue, GlobalAlpha);
            }
            break;

            case 14:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Exclusion);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Exclusion, GlobalAlpha);
            }
            break;

            case 15:
            {
                EffectName   = String.Format(nameFormat, _effectIndex + 1, AppResources.Filter_Blend_Difference);
                _blendEffect = new BlendEffect(_cameraPreviewImageSource, _blendImageProvider, BlendFunction.Difference, GlobalAlpha);
            }
            break;
            }

            if (_blendEffect != null)
            {
                _blendEffect.TargetArea         = _targetArea;
                _blendEffect.TargetAreaRotation = _targetAreaRotation;
            }
        }
        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;
        }