<分区> 分区>
我是 Xamarin Android 的新手,我正在开发用于从服务器获取和显示图像的简单应用程序。 这是我的代码-
public void testWCF2()
{
var imgView = FindViewById<ImageView>(Resource.Id.imageView123);
using(var bm = await GetImageFromUrl(@"http://xamarin.com/content/images/pages/forms/example-app.png")) //At this line an error is showing The 'await' operator can only be used within an async method. Consider marking this method with the 'async' modifier and changing its return type to 'Task'.
imgView.SetImageBitmap(bm);
}
private async Task<Bitmap> GetImageFromUrl(string url)
{
using(var client = new HttpClient())
{
var msg = await client.GetAsync(url);
if (msg.IsSuccessStatusCode)
{
using(var stream = await msg.Content.ReadAsStreamAsync())
{
var bitmap = await BitmapFactory.DecodeStreamAsync(stream);
return bitmap;
}
}
}
return null;
}
有人请帮助我。
谢谢
