【问题标题】:Xamarin Forms - downloading images from Azure to local storage and using as image sourceXamarin Forms - 将图像从 Azure 下载到本地存储并用作图像源
【发布时间】:2018-11-07 19:04:17
【问题描述】:

我有一个功能,可以从 Azure 下载图像并将其保存到名为 appImages 的文件夹中的本地存储中。然后我可以使用下面的代码打开图像并将其设置为图像源。

是否可以将图像保存在与应用程序中相同的位置,即 android/resources/drawable 文件夹中,以便我可以像它们在那里一样引用它们?

我的意思是,我可以这样设置图像源:

myImage.Source = "image01.png";

并且源是从资源文件夹中获取的。我可以下载并保存到任何可以让我像上面那样设置源的位置,而不是我在下面的代码中所做的吗?

IFolder folder = rootFolder ?? FileSystem.Current.LocalStorage;
            IFolder folder2 = await folder.GetFolderAsync("appImages");
            ExistenceCheckResult folderexist = await folder2.CheckExistsAsync(fileName);
            IFile file = await folder2.GetFileAsync(fileName);

            using (System.IO.Stream stream = await file.OpenAsync(PCLStorage.FileAccess.ReadAndWrite))
            {
                long length = stream.Length;
                byte[] streamBuffer = new byte[length];
                stream.Read(streamBuffer, 0, (int)length);
                return streamBuffer;
            }

【问题讨论】:

    标签: c# android xamarin.forms


    【解决方案1】:

    是否可以将图像保存在相同的位置 如果包含在应用程序中,即在 android/resources/drawable 文件夹,这样我就可以像引用它们一样 他们在那里?

    没有。

    应用程序包已签名并且是只读的。您不能在运行时对其进行修改或写入。

    【讨论】:

      猜你喜欢
      • 2018-08-03
      • 2021-06-24
      • 2018-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-04
      相关资源
      最近更新 更多