how to loading images from gallery?

I'm planning an app for cross-platform and i can not loading images from gallery.

Tagged:

Best Answer

Answers

  • lucapasquinilucapasquini USMember ✭✭

    my solution is this

    Button button2 = new Button
    {
    Text = "button",
    FontSize = 30

            };
    
    
    
    
            button2.Clicked += async (sender, args) =>
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("no upload", "picking a photo is not supported", "ok");
                    return;
                }
    
                var file = await CrossMedia.Current.PickPhotoAsync();
                if (file == null)
                    return;
    
                Image1.Source = ImageSource.FromStream(() => file.GetStream());
            };
    
  • dpedrinhadpedrinha DEMember ✭✭✭

    @lucapasquini said:
    my solution is this

    Button button2 = new Button
    {
    Text = "button",
    FontSize = 30

    };

            
    
    
            button2.Clicked += async (sender, args) =>
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("no upload", "picking a photo is not supported", "ok");
                    return;
                }
    
                var file = await CrossMedia.Current.PickPhotoAsync();
                if (file == null)
                    return;
    
                Image1.Source = ImageSource.FromStream(() => file.GetStream());
            };
    

    What is CrossMedia?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @dpedrinha said:

    @lucapasquini said:
    my solution is this

    Button button2 = new Button
    {
    Text = "button",
    FontSize = 30

    };

            
    
    
            button2.Clicked += async (sender, args) =>
            {
                if (!CrossMedia.Current.IsPickPhotoSupported)
                {
                    await DisplayAlert("no upload", "picking a photo is not supported", "ok");
                    return;
                }
    
                var file = await CrossMedia.Current.PickPhotoAsync();
                if (file == null)
                    return;
    
                Image1.Source = ImageSource.FromStream(() => file.GetStream());
            };
    

    What is CrossMedia?

    It's a class from this Nuget
    https://github.com/jamesmontemagno/Xamarin.Plugins/tree/master/Media

  • Dinesh_PhDinesh_Ph INMember ✭✭

    Can we pick multiple images from gallery using this plugin??

  • NagAddalaNagAddala USMember ✭✭

    @Dinesh_Ph
    Check the following link
    https://xamgirl.com/select-multiple-images-from-gallery-in-xamarin-forms/#comment-326
    since ELCImagePicker is not available for iOS this sample works for Android Device only.

  • MeteMete Member ✭✭

    @lucapasquini Once click on the button and load the image to Image1, how do you keep the state when you move back and forward. Is there any solution to that.? Anyone can give advice on that. pls ping me...

Sign In or Register to comment.