/// <summary> /// Get the image and convert it to a byte[] and set it to the rigth properties. /// </summary> private void ProcessingImage(MediaFile file) { if (file == null) { return; } var stream = file.GetStream(); _cachedImage = GetImageStreamAsBytes.Convert(stream); if (_cachedImage != null) { Stream reRead = new MemoryStream(_cachedImage); if (stream != null) { _image = new Image { Source = ImageSource.FromStream(() => reRead), BackgroundColor = Color.Gray, }; UserImage = _image.Source; } } }
public CreateUserViewModel(INavigationService navigationService, IPageDialogService dialogService) { _navigationService = navigationService; _pageDialogservice = dialogService; //setting the display size dependet size of the imageview ImageSectionSize = Xamarin.Forms.DependencyService.Get <IScreenDimensions>().GetScreenHeight() * 0.15; //set the min and max date MinDate = DateTime.Today.AddYears(-99); MaxDate = DateTime.Today.AddYears(-13); //set the min possible age Birthday = MaxDate; //initialize the commands OnSaveClicked = new DelegateCommand(async() => await Task.Run(() => Save())); OnImageChooseTapped = new DelegateCommand(async() => await ChooseImageAsync()); OnCancel = new DelegateCommand(() => Cancel()); //set the default user image _image = new Image { Source = ImageSource.FromResource("Questonaut.SharedImages.defaultUserImage.png") }; Assembly assembly = Assembly.GetExecutingAssembly(); Stream file = assembly.GetManifestResourceStream("Questonaut.SharedImages.defaultUserImage.png"); _cachedImage = GetImageStreamAsBytes.Convert(file); UserImage = _image.Source; }
/// <summary> /// Save the selected image to the firestore cloud. /// </summary> /// <param name="imageStream"></param> /// <returns></returns> private async Task <string> StoreImage(Stream imageStream) { //set the authentication token var options = new FirebaseStorageOptions { AuthTokenAsyncFactory = async() => await Xamarin.Forms.DependencyService.Get <IFirebaseAuthenticator>().GetCurrentUser() }; var storageImage = await new FirebaseStorage("questonaut.appspot.com", options) .Child("UserImages") .Child(CurrentUser.Instance.User.Email + ".jpg") .PutAsync(imageStream); //set the image localy CurrentUser.Instance.User.LocalImage = GetImageStreamAsBytes.Convert(imageStream); return(storageImage); }