/// <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(); }
/// <summary> /// Initialize and start the camera preview /// </summary> public async Task InitializeAsync() { Status = "Starting camera..."; // Create a camera preview image source (from Imaging SDK) _cameraPreviewImageSource = new CameraPreviewImageSource(); DeviceInformationCollection devices = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(Windows.Devices.Enumeration.DeviceClass.VideoCapture); String backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Back).Id; await _cameraPreviewImageSource.InitializeAsync(backCameraId); var properties = await _cameraPreviewImageSource.StartPreviewAsync(); // Create a preview bitmap with the correct aspect ratio var width = 640.0; var height = (width / properties.Width) * properties.Height; var bitmap = new WriteableBitmap((int)width, (int)height); PreviewBitmap = bitmap; // Create a filter effect to be used with the source (no filters yet) _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap); // Attach preview frame delegate _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable; Status = "Initialized"; Initialized = true; }
public async Task ResumePreviewAsync() { if (_initialized) { await _cameraPreviewImageSource.InitializeAsync(string.Empty); await _cameraPreviewImageSource.StartPreviewAsync(); } }
private async void Init() { //Get back camera var devices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); var backCameraId = devices.FirstOrDefault(x => x.EnclosureLocation != null && x.EnclosureLocation.Panel == Panel.Back).Id; //Start preview _cameraPreviewImageSource = new CameraPreviewImageSource(); await _cameraPreviewImageSource.InitializeAsync(backCameraId); var properties = await _cameraPreviewImageSource.StartPreviewAsync(); //Setup preview _width = 640.0; _height = _width / properties.Width * properties.Height; var bitmap = new WriteableBitmap((int)_width, (int)_height); _writeableBitmap = bitmap; PreviewImage.Source = _writeableBitmap; _writeableBitmapRenderer = new WriteableBitmapRenderer(_cameraPreviewImageSource, _writeableBitmap); _cameraPreviewImageSource.PreviewFrameAvailable += OnPreviewFrameAvailable; _videoDevice = (VideoDeviceController)_cameraPreviewImageSource.VideoDeviceController; //Set timer for auto focus if (_videoDevice.FocusControl.Supported) { var focusSettings = new FocusSettings { AutoFocusRange = AutoFocusRange.Macro, Mode = FocusMode.Auto, WaitForFocus = false, DisableDriverFallback = false }; _videoDevice.FocusControl.Configure(focusSettings); _timer = new DispatcherTimer { Interval = new TimeSpan(0, 0, 0, 2, 0) }; _timer.Tick += TimerOnTick; _timer.Start(); } await _videoDevice.ExposureControl.SetAutoAsync(true); _initialized = true; }
/// <summary> /// Initialize and start the camera preview /// </summary> public async Task InitializeAsync() { 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; } }
public override async Task BeginPreviewAsync(object preview) { if (!(preview is Image)) { return; } await InitCamera(); _Rendering = false; _ImagePreview = (Image)preview; _ImagePreview.Source = _Image; _Source.StartPreviewAsync(); }
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; }
/// <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; } }
}//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
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; }
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; }
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; }
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; }