Last active
August 29, 2015 14:17
-
-
Save jonedavis/7adb0249de20ef2a6350 to your computer and use it in GitHub Desktop.
Asynchronously download an image in just a few lines of code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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