In Xamarin, how can I convert a return type of 'System.Threading.Tasks.Task<Android.Graphics.Bitmap>' to 'Android.Graphics.Bitmap'
Here is my method:
private async Task<Bitmap> GetBitmapFromUriAsync(string uri)
{
var client = new HttpClient();
using (var data = await client.GetStreamAsync(uri))
{
if (data != null && data.Length > 0)
{
return await BitmapFactory.DecodeStreamAsync(data);
}
}
return null;
}
I am needing to set the result of the above method to an ImageView
This is the code that I currently have:
gridViewItem.image = GetBitmapFromUriAsync("http://image.png");
Here is the error:
Cannot implicitly convert type 'System.Threading.Tasks.Task<Android.Graphics.Bitmap>' to 'Android.Graphics.Bitmap'
Thanks in advance
EDIT
I have added the await keyword as follows:
gridViewItem.image = await GetBitmapFromUriAsync("http://image.png");
This is the error that I am getting:
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'
How do I modify the return type to be Task, yet still return a Bitmap?
GetBitmapFromUriAsync("http://image.png");is called async