Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

Problem with ImageSource on Xamarin.Android

$
0
0

I'm having trouble loading an image dynamically using ImageSource.
The following code is in a Xamarin.Forms shared project. It displays the appropriate image fine when run on iOS and WinPhone, but displays only an empty area on Android.

var img = new Image();
img.VerticalOptions = LayoutOptions.CenterAndExpand;

img.Source = new StreamImageSource() { Stream = (token) => getImage(token, fld) };

layout.Children.Add(img);

where getImage is

    async Task<Stream> getImage(object token, string base64encodedimage)
    {
        return new MemoryStream(Convert.FromBase64String(base64encodedimage));
    }

I've also tried replacing the img.Source = line with
img.Source = ImageSource.FromStream(() => new MemoryStream(base64encodedimage));
img.Source = ImageSource.FromUri("http://host/location_of_img.jpg")
with the same results.
The only success I had came with inserting the image statically into the Xaml file, ie

<Layout>
...
<Image Source="http://host/location_of_img.jpg" VerticalOptions="CenterAndExpand"/>
...
</Layout>

The image displays fine here but this doesn't allow as easily for dynamically updating the picture (or adding new ones as needed).
I notice in the xamarin.forms samples code, FormsGallery project, ImageDemoPage.cs file that the Device.OnPlatform is used with the Source property for images and the Android call uses FromFile where the other two platforms use FromUri. There doesn't seem to be anything in the documentation about this being a specifically Android issue; has anyone else run into it? Or is there a workaround? Or am I just missing something really obvious? Any suggestions would be welcome. Thanks.


Viewing all articles
Browse latest Browse all 58056

Trending Articles



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