【问题标题】:Download Image from azure blob storage and download it从 azure blob 存储下载图像并下载
【发布时间】:2018-08-03 19:42:51
【问题描述】:

我正在使用 Xamarin 表单,我已经在 Azure blob 存储中存储了一个图像,我想在页面加载时下载它并放入图像视图中,截至目前我有以下代码:

using(var fileStream = imageStore.GetStream())
{
     blockBlob.DownloadToStreamAsync(fileStream);
}

此代码应该将图像下载到文件流中(如果我错了,请告诉我)但是我需要从该文件流中获取图像并将其设置为图像视图源,但我没有不知道该怎么做。

【问题讨论】:

  • ImageSource.FromStream()
  • @Jason 我想你的意思是这样的:image.Source = ImageSource.FromStream(fileStream);在这种情况下,我知道它无法将 system.io.stream 转换为 system.func
  • google 一下,有很多例子

标签: azure xamarin xamarin.forms azure-storage azure-mobile-services


【解决方案1】:

您可以通过静态方法ImageSource.FromStream直接将流转换为Image.Source

using (var fileStream = new MemoryStream())
{
    await blockBlob.DownloadToStreamAsync(fileStream);
    image.Source = ImageSource.FromStream(() => fileStream);
}

注意:DownloadToStreamAsync 返回一个Task,所以await 它...

【讨论】:

  • 我试过了,但它给了我:无法将 system.io.stream 转换为 system.func
  • @AppleGeek 错字,因为我是从头顶开始做的,它应该是一个函数......
  • 图像不会弹出并在输出窗口中显示:ImageLoaderSourceHandler: Image data was invalid: Xamarin.Forms.StreamImageSource
  • @AppleGeek,在使用流获取图像源((...)FromStream(() => fileStream))之前,请尝试将其位置设置为零:fileStream.Position = 0;
  • @AppleGeek 你确定有一个有效的图像存储在 Azure 上吗?尝试将字节数组转换为 Base64String 并在在线工具上进行测试。寿司的答案应该有效
猜你喜欢
  • 2018-11-21
  • 1970-01-01
  • 2019-04-06
  • 2012-12-08
  • 2019-12-19
  • 2019-09-05
  • 2021-12-12
  • 1970-01-01
  • 2021-12-08
相关资源
最近更新 更多