2

I am working with xamarin.forms and using this code to get an image from user gallery

 protected async Task PickImage()
    {
        try
        {
            Stream stream = await DependencyService.Get<IPicturePicker>().GetImageStreamAsync();
            //stream.GetType<Uri>();
            if (stream != null)
            {
                Image image = new Image
                {
                    Source = ImageSource.FromStream(() => stream),
                    BackgroundColor = Color.Gray
                };

                cadastrar_foto_perfil.Source = ImageSource.FromStream(() => stream);

            }

            if (Device.OS == TargetPlatform.iOS)
            {
                loginPage.RecriaCadastroIOS();
            }
        }

but...Now I am getting it am putting in an Image, now I need to get the URI from the selected image...does someone know how I can do this using that code?

Joyce de Lanna
  • 1,473
  • 2
  • 15
  • 39
  • 1
    you can get an Uri when you store the image as a file (and/or broadcast it to the gallery), using `Android.Net.Uri.FromFile(image_filename);` but as far as I can see you're doing all in-memory, and the image stream has no "address" that could be expressed as a Uri. Would the `PicturePicker` not have a FileName or Uri property? – Cee McSharpface Aug 20 '17 at 18:59
  • I dont know if it has – Joyce de Lanna Aug 20 '17 at 19:29
  • and I can't use "android" because this code is to ios and android too – Joyce de Lanna Aug 20 '17 at 19:31
  • the forms `IPicturePicker` returns a stream only. Using this approach, there is no way to get the Uri without using platform specific code. There ([android example again](https://developer.xamarin.com/recipes/android/data/files/selecting_a_gallery_image/)), the `ActionGetContent` calls back with an Uri. – Cee McSharpface Aug 20 '17 at 21:14

0 Answers0