我该如何在Xamarin Forms中使用位图?这个在我的Android项目中曾经用过,但我想从Xamarin Forms中使用类似的东西。我不想做任何渲染或平台特定的操作。如果我能在Forms中完成,那就太好了。你有什么想法吗?
private async void GetIcon()
{
Weather weather = await Core.GetWeather();
var bitmap = new Image { Source = ImageSource.FromUri(new Uri("http://openweathermap.org/img/w/" + weather.Icon + ".png")) };
DisplayIcon.bitmap ?
}
XAML:
<Image x:Name="DisplayIcon" Source ="{Binding bitmap}" />
ends here *******
****old post****
private Bitmap GetImageBitmapFromUrl(string url)
{
Bitmap imageBitmap = null;
using (var webClient = new WebClient())
{
var imageBytes = webClient.DownloadData(url);
if (imageBytes != null && imageBytes.Length > 0)
{
imageBitmap = BitmapFactory.DecodeByteArray(imageBytes, 0, imageBytes.Length);
}
}
return imageBitmap;
}
private async void displayIcon()
{
Weather weather = await Core.GetWeather();
if (weather != null)
{
var bitmap = GetImageBitmapFromUrl("http://openweathermap.org/img/w/" + weather.Icon + ".png");
Icon2.SetImageBitmap(bitmap);
}
}