【发布时间】:2021-06-20 13:46:02
【问题描述】:
我想显示已成功存储到 Firebase 存储中的图像。我让用户从图库中选择图像并将其保存在数据库中。然后我将 URL 链接保存在实时数据库中,我认为我可以绑定到 image.source 但这不起作用。我还尝试将链接从 firebase 控制台直接复制到 XAML 中,但没有成功。我还尝试将图像下载到手机上(下面的代码),但是这不起作用。我在任何地方都找不到任何教程来为 Xamarin 表单显示来自 firebase 的图像。我有点卡在这里。
public void LoadImages(string imgurl)
{
var webClient = new WebClient();
byte[] imgBytes = webClient.DownloadData(imgurl);
//string img = Convert.ToBase64String(imgBytes);
petimage.Source = ImageSource.FromStream(() => new MemoryStream(imgBytes));
}
protected override void OnAppearing()
{
base.OnAppearing();
RetrivePetInfo();
}
private async void RetrivePetInfo()
{
var pet = await firebaseHelper.GetPet(PetName);
if (pet != null)
{
if(pet.imageUrl!=null)
{
LoadImages(pet.imageUrl);
}
}
}
【问题讨论】:
-
你搜索过类似的问题吗?这些有帮助吗? stackoverflow.com/questions/61539184/… , stackoverflow.com/questions/45897548/…
-
你能得到imgBytes的值吗?
标签: c# firebase xamarin.forms