private async void TakePictureAsync() { try { var stream = await _pictureChooserTask.TakePictureAsync(400, 95); var memoryStream = new MemoryStream(); await stream.CopyToAsync(memoryStream); int sequenceNumber = (ImagesVM.Any()) ? _imagesVM.Max(i => i.Image.Sequence) + 1 : 1; Image image = new Image() { ID = Guid.NewGuid(), Sequence = sequenceNumber, Bytes = memoryStream.ToArray(), Filename = string.Format("{0} {1}.jpg", _infoService.CurrentDriverDisplayName, DateTime.Now.ToString("yyyy-MM-ddHH-mm-ss")) }; //Add to view model CameraImageViewModel imageViewModel = new CameraImageViewModel(image, this); ImagesVM.Add(imageViewModel); RaisePropertyChanged(() => HasPhotoBeenTaken); RaisePropertyChanged(() => CommentHintText); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// Deletes an image from both the the view models and datamodels /// </summary> /// <param name="image"></param> internal void Delete(CameraImageViewModel image) { // remove view model ImagesVM.Remove(image); RaisePropertyChanged(() => HasPhotoBeenTaken); RaisePropertyChanged(() => CommentHintText); }
/// <summary> /// Packs up the image stre /// </summary> /// <param name="stream"></param> private void OnPictureTaken(Stream stream) { var memoryStream = new MemoryStream(); stream.CopyTo(memoryStream); int sequenceNumber = (ImagesVM.Any()) ? _imagesVM.Max(i => i.Image.Sequence) + 1 : 1; Image image = new Image() { ID = Guid.NewGuid(), Sequence = sequenceNumber, Bytes = memoryStream.ToArray(), Filename = string.Format("{0} {1}.jpg", _infoService.CurrentDriverDisplayName, DateTime.Now.ToString("yyyy-MM-ddHH-mm-ss")) }; //Add to view model CameraImageViewModel imageViewModel = new CameraImageViewModel(image, this); ImagesVM.Add(imageViewModel); RaisePropertyChanged(() => HasPhotoBeenTaken); RaisePropertyChanged(() => CommentHintText); }