private async void EditUserIcon_Tabbed(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Alert", "not supprored", "ok"); return; } var mediaoptions = new Plugin.Media.Abstractions.PickMediaOptions() { PhotoSize = PhotoSize.Medium }; selectedimgfile = await CrossMedia.Current.PickPhotoAsync(mediaoptions); if (selectedimgfile == null) { await DisplayAlert("error", "tryagain", "ok"); } RelativeImage.Source = ImageSource.FromStream(() => selectedimgfile.GetStream()); Stream stream = selectedimgfile.GetStream(); var imagePath = await UserProfileViewModel.UploadImage(stream, selectedimgfile.Path); var userID = int.Parse(Application.Current.Properties["UserID"].ToString()); Relative.Image = App.ServiceURL + imagePath; Relative = await UserProfileViewModel.EditUser(Relative, Relative.ID); RelativeImage.Source = Relative.Image; }
public static async Task <MediaFile> PickPhoto() { // Select a photo. if (CrossMedia.Current.IsPickPhotoSupported) { var mediaOptions = new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = PhotoSize.Small }; MediaFile photo = await CrossMedia.Current.PickPhotoAsync(mediaOptions); return(photo); } else { return(null); } // Select a video. //if (CrossMedia.Current.IsPickVideoSupported) // MediaFile video = await CrossMedia.Current.PickVideoAsync(); }
public async Task <byte[]> SendPicture(bool camera) { if (CrossMedia.Current.IsCameraAvailable && CrossMedia.Current.IsTakePhotoSupported) { //Supply media options for saving our photo after it's taken. var pictureMediaOptions = new Plugin.Media.Abstractions.StoreCameraMediaOptions { Directory = "Receipts", Name = $"{DateTime.UtcNow}.jpg", PhotoSize = PhotoSize.Small }; var galleryMediaOptions = new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = PhotoSize.Small }; // Take a photo of the business receipt. MediaFile file; if (camera) { file = await CrossMedia.Current.TakePhotoAsync(pictureMediaOptions); } else { file = await CrossMedia.Current.PickPhotoAsync(galleryMediaOptions); } if (file != null) { var stream = file.GetStream(); file.Dispose(); byte[] imageData = GetImageStreamAsBytes(stream); return(imageData); } return(null); } return(null); }