How to load image asynchronously from URI in Xamarin formats
Here is my current code for loading the image:
System.Uri uri;
System.Uri.TryCreate (imageURI, UriKind.Absolute, out uri);
_companyImage.Source = ImageSource.FromUri (uri);
The problem is that the whole program has to wait for this task to complete, I would like to load the image asynchronously, but I cannot work out how to create the image source asynchronously.
+3
source to share
3 answers
Animate the data asynchronously and assign it to your source as soon as it's done.
System.Uri uri;
System.Uri.TryCreate(imageURI, UriKind.Absolute, out uri);
Task<ImageSource> result = Task<ImageSource>.Factory.StartNew(() => ImageSource.FromUri(uri));
_companyImage.Source = await result;
+4
source to share
You can simply set the property Image.Source
to a URI and let Xamarin.Forms do the work for you (behind "Working with Images" in Xamarin. Document Forms ).
Example
var someImage = new Image() {
Aspect = Aspect.AspectFit,
Source = ImageSource.FromUri(new Uri("http://xamarin.com/content/images/pages/branding/assets/xamagon.png")),
};
+3
source to share
Set your url to the original property or bind it from viewmodel
https://developer.xamarin.com/guides/xamarin-forms/user-interface/images/
<Image Source="yoururl" Aspect="AspectFill" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand"/>
0
source to share