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 can't work out how to create an image source asynchronously.
Grab the data asynchronously and assign it to your Source once it is 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;
You can simply set the Image.Source
property to a URI and let Xamarin.Forms do the work for you (per "Working with Images" in Xamarin.Forms docs).
var someImage = new Image() {
Aspect = Aspect.AspectFit,
Source = ImageSource.FromUri(new Uri("http://xamarin.com/content/images/pages/branding/assets/xamagon.png")),
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With