public bool TakePicture(string controlId, out Bitmap bitmap, int ordinal, string parentId) { var command = new TakePictureCommand { AutomationIdentifier = CreateAutomationIdentifier(controlId), Ordinal = ordinal, ParentIdentifier = CreateAutomationIdentifier(parentId) }; var result = SyncExecuteCommand(command); var pictureResult = result as PictureResult; if (pictureResult == null) { // TODO - should log the result here really bitmap = null; return(false); } var bytes = Convert.FromBase64String(pictureResult.EncodedPictureBytes); var memoryStream = new MemoryStream(bytes); bitmap = new Bitmap(memoryStream); return(true); }
public override void Initialize() { _logger.Trace("Инициализация"); _imageProcessor.TimerElapsed += ImageProcessorOnTimerElapsed; _imageProcessor.CameraErrorEvent += ImageProcessorOnCameraErrorEvent; _imageProcessor.ImageChanged += ImageProcessorOnStreamChanged; _imageProcessor.ImageNumberChanged += ImageProcessorOnImageNumberChanged; Capturing = false; _imageProcessor.InitializeProcessor(); OpenSession(); if (!_sessionOpened) { _dialogService.ShowInfo("Камера не готова, попробуйте ещё раз."); _logger.Trace("Неудачная поптыка открытия сессии"); return; } _settings = _settingsProvider.GetCameraSettings(); if (_settings != null) { _logger.Trace("Применение настроек для камеры"); //_imageProcessor.SetSetting((uint)PropertyId.AEMode, (uint)_settings.SelectedAeMode); TODO Не поддерживается. _imageProcessor.SetSetting((uint)PropertyId.WhiteBalance, (uint)_settings.SelectedWhiteBalance); _imageProcessor.SetSetting((uint)PropertyId.Av, (uint)_settings.SelectedAvValue); _imageProcessor.SetSetting((uint)PropertyId.ExposureCompensation, (uint)_settings.SelectedCompensation); _imageProcessor.SetSetting((uint)PropertyId.ISOSpeed, (uint)_settings.SelectedIsoSensitivity); _imageProcessor.SetSetting((uint)PropertyId.Tv, (uint)_settings.SelectedShutterSpeed); } _cameraStreamSynchronize = new AutoResetEvent(false); _logger.Trace("Запуск LiveView"); StartLiveView(); var cancellTokenSource = new CancellationTokenSource(); if (TakePictureCommand.CanExecute(cancellTokenSource.Token)) { try { TakePictureCommand.Execute(cancellTokenSource.Token); } catch (Exception ex) { //_dialogService.ShowInfo("Упс... С камерой возникли неполадки. Приносим свои извинения. =("); _logger.Error(ex, "Ошибка при инициализации камеры"); GoBack(); } } else { //_dialogService.ShowInfo("Упс... С камерой возникли неполадки. Приносим свои извинения. =("); _logger.Trace("TakePictureCommand.CanExecute вернул false"); GoBack(); } }
/// <summary> /// Makes from a string and value a command /// </summary> /// <param name="command"></param> /// <param name="value"></param> /// <returns>Command</returns> public IDroneCommand makeCommand(string command, double value = 0) { IDroneCommand droneCommand = null; if (command.Equals("Start")) { droneCommand = new StartCommand(_droneController); } else if (command.Equals("Land")) { droneCommand = new LandCommand(_droneController); } else if (command.Equals("Rise")) { droneCommand = new RiseCommand(_droneController, value); } else if (command.Equals("Fall")) { droneCommand = new FallCommand(_droneController, value); } else if (command.Equals("Right")) { droneCommand = new RightCommand(_droneController, value); } else if (command.Equals("Left")) { droneCommand = new LeftCommand(_droneController, value); } else if (command.Equals("Forward")) { droneCommand = new ForwardCommand(_droneController, value); } else if (command.Equals("Backward")) { droneCommand = new BackwardCommand(_droneController, value); } else if (command.Equals("Turn")) { droneCommand = new TurnCommand(_droneController, (int)value); } else if (command.Equals("TakePicture")) { droneCommand = new TakePictureCommand(_droneController, (int)value); } else if (command.Equals("FollowLine")) { droneCommand = new FollowLineCommand(_droneController); } return(droneCommand); }
public async Task ExecuteTakePictureCommand(string isSelfie) { if (IsBusy) { return; } IsBusy = true; TakePictureCommand.ChangeCanExecute(); var error = false; try { if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { var page = new ContentPage(); IsBusy = false; TakePictureCommand.ChangeCanExecute(); await page.DisplayAlert("No Camera", ":( No camera avaialble.", "OK"); return; } var opts = new Plugin.Media.Abstractions.StoreCameraMediaOptions() { Directory = "Sample", Name = "test.jpg" }; if (isSelfie.Equals("true")) { opts.DefaultCamera = Plugin.Media.Abstractions.CameraDevice.Front; } var file = await CrossMedia.Current.TakePhotoAsync(opts); if (file == null) { IsBusy = false; TakePictureCommand.ChangeCanExecute(); return; } MyImageSource = ImageSource.FromStream(() => { var stream = file.GetStream(); return(stream); }); } catch { error = true; } if (error) { var page = new ContentPage(); await page.DisplayAlert("Error", "Unable to Take Picture", "OK"); } IsBusy = false; TakePictureCommand.ChangeCanExecute(); }
public bool TakePicture(string controlId, out Bitmap bitmap, int ordinal, string parentId) { var command = new TakePictureCommand { AutomationIdentifier = CreateAutomationIdentifier(controlId), Ordinal = ordinal, ParentIdentifier = CreateAutomationIdentifier(parentId) }; var result = SyncExecuteCommand(command); var pictureResult = result as PictureResult; if (pictureResult == null) { // TODO - should log the result here really bitmap = null; return false; } var bytes = Convert.FromBase64String(pictureResult.EncodedPictureBytes); var memoryStream = new MemoryStream(bytes); bitmap = new Bitmap(memoryStream); return true; }