Reputation: 47
Can anybody give me an example how I would download an image asynchroniously and display it in an ImageView in MonoDroid.
Im tyring to port an project from MonoTouch to MonoDroid, but I'm having quite some problems with this part...
Upvotes: 2
Views: 560
Reputation: 1258
Maybe this is what you are looking for:
public class Activity1 : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
this.SetContentView(Resource.Layout.layout1);
WebClient web = new WebClient();
web.DownloadDataCompleted += new DownloadDataCompletedEventHandler(web_DownloadDataCompleted);
web.DownloadDataAsync(new Uri(@"http://your.image.com"));
}
void web_DownloadDataCompleted(object sender, DownloadDataCompletedEventArgs e)
{
Bitmap bm = BitmapFactory.DecodeByteArray(e.Result, 0, e.Result.Length);
FindViewById<ImageView>(Resource.Layout.layout1).SetImageBitmap(bm);
}
}
I haven't tested this one, but I think it should do the job :)
/Nicklas
Upvotes: 1