如何在 WPF 应用程序中将图像源的 URI 设置为根目录(即与您的 exe 相同的文件夹)?
var myImage = new Image();
myImage.Source = new BitmapImage(new Uri("pack://application:,,,/AssemblyName;component/speedline.png", UriKind.Absolute));
我已经尝试了上述方法并不断收到以下错误消息:
mscorlib.dll 中出现类型为“System.IO.FileNotFoundException”的未处理异常。 附加信息:无法加载文件或程序集“AssemblyName,Culture=neutral”或其依赖项之一。系统找不到指定的文件。
我显然做错了什么,但可以保证可以在 C:\Users\Admin\Documents\Visual Studio 2013\Projects\Speedy\Speedy\bin\Debug
找到 png 文件>,在与我的 exe 文件相同的文件夹中,但我如何引用它?
最佳答案
在名为 component 的解决方案资源管理器下创建一个新文件夹,并在其下添加现有图像。现在尝试使用相对路径。
myImage = new BitmapImage(new Uri("/component/speedline.png", UriKind.Relative));
关于c# - 图片源应用设置URI为根目录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25984687/