2011-10-11 40 views
2

任何人都可以給我一個例子,我將如何異步下載圖像並將其顯示在MonoDroid的ImageView中。在MonoDroid中的異步ImageView

林tyring端口一個項目從MonoTouch的到MonoDroid的,但我有這個部分頗有些問題......

回答

1

也許這是你在找什麼:

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); 
    } 
} 

我沒有測試過這一個,但我認爲它應該做的工作:)

/尼克拉斯