Last active
August 29, 2015 14:05
Async image downloading for monotouch
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
byte[] data = null; | |
using (Stream response = await session.DownloadResourceAsync(request)) | |
using (MemoryStream responseInMemory = new MemoryStream()) | |
{ | |
await response.CopyToAsync(responseInMemory); | |
data = responseInMemory.ToArray(); | |
} | |
BeginInvokeOnMainThread(delegate | |
{ | |
using ( NSData imageData = NSData.FromArray(data) ) | |
{ | |
using ( UIImage image = new UIImage(imageData) ) | |
{ | |
// no need disposing | |
// since this.ImageView.Image creates a | |
// new C# object on each call | |
this.ImageView.Image = image; | |
// Update Overlay | |
this.HideLoader(); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment