Skip to content

Instantly share code, notes, and snippets.

@dodikk
Last active August 29, 2015 14:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dodikk/681621970afbcb776831 to your computer and use it in GitHub Desktop.
Save dodikk/681621970afbcb776831 to your computer and use it in GitHub Desktop.
Async image downloading for monotouch
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