Skip to content

Instantly share code, notes, and snippets.

@jonedavis
Last active August 29, 2015 14:17
Show Gist options
  • Save jonedavis/7adb0249de20ef2a6350 to your computer and use it in GitHub Desktop.
Save jonedavis/7adb0249de20ef2a6350 to your computer and use it in GitHub Desktop.
Asynchronously download an image in just a few lines of code
using System;
using System.Threading.Tasks;
using System.Net.Http;
using UIKit;
using Foundation;
namespace AsyncImageDownload
{
public class ImageDownloader
{
public async Task<UIImage> GetAsync (Uri uri)
{
var bytes = await new HttpClient ().GetByteArrayAsync (uri);
var data = NSData.FromArray (bytes);
return UIImage.LoadFromData (data);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment