我正在尝试使用这样的 BitmapImages 创建一个列表。
List<BitmapImage> Images = new List<BitmapImage>
{
new BitmapImage(new Uri(@"/Images/Car.bmp", UriKind.Relative)),
};
现在我正在从资源\Images\中手动添加一张图片,但我不想对所有 68 张图片都这样做。 有没有办法制作一个方法,它将查看资源\Images\,并像上面那样输出所有 BitmapImage 路径的列表?
类似的东西。
Foreach(Item in Images)
{
List.add(ItemPath + ItemName)
}
这是我正在谈论的文件夹的图片:
最佳答案
这里是如何通过模式获取文件
string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Images");
foreach (string file in Directory.GetFiles(path, "*.bmp"))
{
// there is file name
}
关于c# 如何获取资源文件夹中所有项目的文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49253629/