我的目标是获取每个项目图像文件夹中保存的嵌入式图像,流式传输它,将其转换为字节数组,并使用PCLStorage将其保存到设备的本地存储文件系统中。我无法弄清楚的部分是如何从嵌入式图像进行流式传输。
var embeddedImage = new Image { Aspect = Aspect.AspectFit };
embeddedImage.Source = ImageSource.FromResource("applicationIcon.png");
如果我有路径,我就可以流式传输它,或者如果我有流,我就可以将其转换为byte[]
。由于文件源未找到(显然),因此下面的代码无法工作。
string localFileUri = string.Empty;
// Get hold of the file system.
IFolder localFolder = FileSystem.Current.LocalStorage;
IFile file = await FileSystem.Current.GetFileFromPathAsync("applicationIcon.png");
using (Stream stream = await file.OpenAsync(FileAccess.Read))
{
using (var ms = new MemoryStream())
{
var byteArray = ms.ToArray();
var storeragePath = await iStorageService.SaveBinaryObjectToStorageAsync(string.Format(FileNames.ApplicationIcon, app.ApplicationId), byteArray);
app.IconURLLocal = storeragePath;
}
}
唯一的选择似乎是使用某种资源定位符,然后为您添加的每种类型的项目维护该代码。不太优雅,是否有其他方法?