It has been 4 years since this question has been answered with this blog post.
Is there a standard way to create a UIImage with an image from a URL? Something like:
UIImage image = UIImage.FromFile("http://foo.com/bar.jpg");
I feel like I'm probably missing something really simple.
Not a one-liner, but with very few lines you can roll your own. E.g.
The calls, including the one from
UIImage
, are thread-safe.I tried the above, it looks like a great idea, but I get: Cannot implicitly convert type
System.Threading.Tasks.Task<MonoTouch.UIKit.UIImage>' to
Monotouch.UIKit.UIImage'[found a solution] The problem was because the
obj.Image = await this.LoadImage (imageUrl) must also be in a method marked async. Then it works!
Thanks
You want to be sure that you load the image async so that you do not block your UI thread. MonoTouch.Dialog includes an ImageLoader (see sec 5.3) class that you could use.
There are also a couple of variations of UrlImageStore out there to help with async loading images.
Finally, if you want to do it manually, there is a Xamarin Recipe you can use.
With new await/async support you can do:
and you call this with: