繁体   English   中英

将URI设置为图像源应用程序中的根目录

[英]Setting URI to root directory in application for image source

如何在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'或其依赖项之一。 该系统找不到指定的文件。

我显然做错了什么,但可以保证png文件可以在exe文件所在的文件夹中的C:\\Users\\Admin\\Documents\\Visual Studio 2013\\Projects\\Speedy\\Speedy\\bin\\Debug中找到,但是我该如何引用呢?

在称为组件的解决方案资源管理器下创建一个新文件夹,并在该文件夹下添加现有图像。 现在尝试使用相对路径。

myImage = new BitmapImage(new Uri("/component/speedline.png", UriKind.Relative));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM