UWP:从基于比例的资产中检索正确的文件 name/path
UWP: Retrieve correct file name/path from scale-based asset
目前我以这种方式从XAML检索文件路径:
var myFile = System.IO.Path.Combine(Package.Current.InstalledLocation.Path, fileImage.File);
因为在 XAML 中文件名是例如icon.png
而不是 icon.scale-150.png
它找不到图像,当我想将它读入流时。如何从基于比例的资产中检索正确的文件 name/path?
它必须采用通用路径并将其转换为基于比例的路径。有办法吗?我找不到一个。
如果icon.png位于Assets文件夹中,您可以直接使用ms-appx协议获取URI,这样:
var file = new Uri("ms-appx:///Assets/icon.png");
这将根据设备检索具有正确比例的图标。
目前我以这种方式从XAML检索文件路径:
var myFile = System.IO.Path.Combine(Package.Current.InstalledLocation.Path, fileImage.File);
因为在 XAML 中文件名是例如icon.png
而不是 icon.scale-150.png
它找不到图像,当我想将它读入流时。如何从基于比例的资产中检索正确的文件 name/path?
它必须采用通用路径并将其转换为基于比例的路径。有办法吗?我找不到一个。
如果icon.png位于Assets文件夹中,您可以直接使用ms-appx协议获取URI,这样:
var file = new Uri("ms-appx:///Assets/icon.png");
这将根据设备检索具有正确比例的图标。