Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

How I can rename photo in Xamarin media plugin using PickPhotoAsync

$
0
0

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);


                                }

Viewing all articles
Browse latest Browse all 204402

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>