【问题标题】:Problem with image path [C#, WPF]图像路径问题 [C#, WPF]
【发布时间】:2010-11-16 15:05:30
【问题描述】:

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

**AppFolder** 包含这些文件和一个子文件夹(头像): -myApp.exe -myDll.dll -avatars {文件夹} 包括: -manImages.jpg -womanImages.jpg

我尝试这种格式的用户 uri

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

但是这种格式不起作用,图像是空的。

【问题讨论】:

    标签: c# wpf uri relative-path wpf-4.0


    【解决方案1】:

    我期待

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

    上班?

    你也可以试试:

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

    【讨论】:

    • 我的印象是他希望新的 URL 语句起作用。这是对那个问题的回答。我错过了什么吗?
    • Hogan,在我的问题中,@"C:\Users\avatars\manImages.jpg" 中有错误,它应该是 avatars\manImages。但它不起作用。这个替代: return new Uri(Environment.CurrentDirectory + @"\avatars\man.jpg", UriKind.RelativeOrAbsolute);工作品。谢谢。
    【解决方案2】:

    在 dll 方面你可以这样写:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-20
      • 1970-01-01
      • 2011-01-25
      • 1970-01-01
      • 2011-06-29
      • 2018-07-01
      • 2010-11-29
      • 2010-11-10
      相关资源
      最近更新 更多