Xamarin Forms - 来自文件系统的 FileImageSource?

Xamarin Forms - FileImageSource from File System?

我正在尝试为工具栏项设置图标,但遇到了麻烦。我想从用户下载的 "icon pack" 加载图像。我已正确下载图标,但它们似乎无法加载显示。

var tb = new Forms.ToolbarItem();
tb.Icon = new Forms.FileImageSource { File = "add.png" };

但是,当我手动将它们标记为构建中的 android 资源时,它似乎确实有效(我认为我无法允许用户使用 "icon packs") .本地文件不能使用FileImageSource吗?

FileImageSource 不适用于来自应用程序包外部的路径。如果要加载不在包中的图像,请使用 StreamImageSource 并使用 DependencyService 为每个平台提供来自路径的流。