子文件夹中位图的 URI (c# wpf)

发布于 2024-09-05 04:23:45 字数 694 浏览 2 评论 0原文

我有一个 wpf 应用程序,我正在其中使用图像。要引用我使用的图像:

Uri uri = new Uri("pack://application:,,,/assemblyName;Component/myIcon.png");
BitmapImage(uri)

如果我将 png 直接添加到 csproj 文件下(及其属性 BuildAction=Resource),那么它可以正常工作。

但我想将其移动到 csproj 下的子文件夹中。另一个关于位图\uri 的问题 (857732 )以及链接到此 msdn 的答案。所以我尝试了:

Uri uri = new Uri("pack://application:,,,/assemblyName;Component/Icons/myIcon.png");

但这没有用。

有什么想法吗?

I have a wpf app where I'm using an image. To reference the image I use:

Uri uri = new Uri("pack://application:,,,/assemblyName;Component/myIcon.png");
BitmapImage(uri)

If I add the png directly under the csproj file (with its properties BuildAction=Resource) then it works fine.

But I want to move it to a subfolder under the csproj. Another SO question asked about bitmaps\uri's (857732) and an answer linked to this msdn. So I tried :

Uri uri = new Uri("pack://application:,,,/assemblyName;Component/Icons/myIcon.png");

But that did not work.

Any ideas?

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

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

发布评论

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

评论(1

絕版丫頭 2024-09-12 04:23:45

如果图像在您的解决方案中(即,您没有从另一个程序集引用图像),您应该能够使用此语法:

Uri uri = new Uri("pack://application:,,,/Icons/myIcon.png", UriKind.Absolute);

或者,您可以使用相对 Uri,如下所示:

Uri uri = new Uri("/Icons/myIcon.png", UriKind.Relative);

If the image is in your solution (i.e., you are not referencing the image from another assembly), you should be able to use this syntax:

Uri uri = new Uri("pack://application:,,,/Icons/myIcon.png", UriKind.Absolute);

Or, you can use a relative Uri as follows:

Uri uri = new Uri("/Icons/myIcon.png", UriKind.Relative);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文