I am working on Xamarin forms. I have notes field; 'Take Photo' button and 'Pick From Gallery' button.
What I want to do is when user take or select photo and click save button; that photo should be renamed as whatever text user type in notes field.
When user take new photo; The text from notes field is getting renamed fine as I wanted.
However, When I select photo from gallery; How I can rename photo to user notes field.
I have researched and tried couple of things but they didn't worked.
This is when user 'Take Photo' and click save button.
private async void Take_Photo_Button_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported) { await DisplayAlert("No Camera", ":( No camera available.", "OK"); return; } var file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions { SaveToAlbum = true, Name = jobnoentry.Text + "-" + Applicationletterentry + "-" + signnoentry.Text + "-" + SignType, }); if (file == null) return; MainImage.Source = ImageSource.FromStream(() => { var stream = file.GetStream(); return stream; }); }
'Name' attribute save the photo to that name.
HOWEVER, When I click 'Pick From Gallery'; I select image; and click save button. How I can Name the image.
The only attributes I get in the 'PickPhotoAsync' or Photo.Size.
This is my code to select from gallery and save.
private async void Select_From_Gallery_Button_Clicked(object sender, EventArgs e) { await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsPickPhotoSupported) { await DisplayAlert("Photos Not Supported", ":( Permission not granted to photos.", "OK"); return; } Stream stream = null; var file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { //No attribute for photo name }); if (file == null) return; stream = file.GetStream(); file.Dispose(); MainImage.Source = ImageSource.FromStream(() => stream); }