我正在尝试创建一个需要我将图像临时写入磁盘的自定义,因为我正在使用仅将对象作为参数ImageFilter
的第三方库。FileInfo
我希望我可以IStorageProvider
用来轻松编写和获取文件,但我似乎无法找到一种方法来转换IStorageFile
或FileInfo
获取当前租户的 Media 文件夹的完整路径来自己检索文件。
public class CustomFilter: IImageFilterProvider {
public void ApplyFilter(FilterContext context)
{
if (context.Media.CanSeek)
{
context.Media.Seek(0, SeekOrigin.Begin);
}
// Save temporary image
var fileName = context.FilePath.Split(new char[] { '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
if (!string.IsNullOrEmpty(fileName))
{
var tempFilePath = string.Format("tmp/tmp_{0}", fileName);
_storageProvider.TrySaveStream(tempFilePath, context.Media);
IStorageFile temp = _storageProvider.GetFile(tempFilePath);
FileInfo tempFile = ???
// Do all kinds of things with the temporary file
// Convert back to Stream and pass along
context.Media = tempFile.OpenRead();
}
}
}
FileSystemStorageProvider
做了很多繁重的工作来构建 Media 文件夹的路径,所以很遗憾它们不能公开访问。我宁愿不必复制所有初始化代码。有没有一种简单的方法可以直接访问 Media 文件夹中的文件?