图像路径问题 [C#、WPF]

发布于 2024-10-02 17:22:51 字数 427 浏览 0 评论 0原文

我需要在 2 个 .NET 程序集中使用图像。第一个是 WPF 应用程序 {myApp.exe},第二个是 *.dll {myDll.dll}。文件位于此文件结构中:

 **AppFolder** consist these files and one subfolder(avatars):

    -myApp.exe
    -myDll.dll
    -avatars {folder} consist:
          -manImages.jpg
          -womanImages.jpg

我尝试采用此格式的用户 uri

new Uri(@"C:\Users\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

,但此格式不起作用,图像为空。

I need use images in 2 .NET assemblies. One is WPF app {myApp.exe} and second is *.dll {myDll.dll}. File are located in this file structure:

 **AppFolder** consist these files and one subfolder(avatars):

    -myApp.exe
    -myDll.dll
    -avatars {folder} consist:
          -manImages.jpg
          -womanImages.jpg

I try user uri in this format

new Uri(@"C:\Users\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

but this format does not work, images are empty.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

爱格式化 2024-10-09 17:22:51

我期望

new Uri(@"avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

工作吗?

您还可以尝试:

new Uri(Environment.CurrentDirectory + @"\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

I would expect

new Uri(@"avatars\manImages.jpg", UriKind.RelativeOrAbsolute);

to work?

You could also try:

new Uri(Environment.CurrentDirectory + @"\avatars\manImages.jpg", UriKind.RelativeOrAbsolute);
骄兵必败 2024-10-09 17:22:51

在dll端你可以这样写:

string imgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "avatars\\manImages.jpg");

On the dll side you can write this:

string imgPath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "avatars\\manImages.jpg");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文