【发布时间】:2018-07-24 04:22:17
【问题描述】:
如何使用 Xamarin Forms 中的位图?这曾经在我的 Android 项目中,但我想使用 Xamarin 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}" />
到此结束 *******
****旧帖****
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);
}
}
【问题讨论】:
标签: bitmap xamarin.forms icons