gpt4 book ai didi

visual-studio - Visual Studio : How to store an image resource as an Embedded Resource?

转载 作者:行者123 更新时间:2023-12-03 11:04:57 25 4
gpt4 key购买 nike

默认情况下,当您将图像(图标、位图等)作为资源添加到项目时,图像的 构建操作 设置为 .这样做是因为图像神奇地存储在 .resources 文件中。

希望将资源存储为嵌入式资源(我的原因无关紧要,但让我们假设这样我可以在 RedGate's Reflector 中看到它们)。

所以我改变了每张图片的 构建操作 嵌入式资源 ,然后资源就会出现在 Lutz 的 Reflector 中——正如我想要的那样。

不幸的是 , Microsoft says specifically not to do this :

Note that when the resource editor adds an image, it sets Build Action to None, because the .resx file references the image file. At build time, the image is pulled into the .resources file created out of the .resx file. The image can then easily be accessed via the strongly-typed class auto-generated for the .resx file.

Therefore, you should not change this setting to Embedded Resource, because doing so would include the image twice in the assembly.



那么什么是 有道将图像作为嵌入资源包含在内?

最佳答案

注意:此答案不是处理图像资源的推荐方式。它只是解决问题所描述的特定问题(即将图像作为嵌入资源包含在内)。

不要将图像添加为资源。我宁愿做以下事情:

  • 创建图像/图标并将其保存到文件
  • 选择 Project -> Add Existing Item 并添加文件
  • 将构建操作设置为嵌入式资源

  • 然后,您可以使用访问此资源
    Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceUri)

    这样,图像不会神奇地添加到项目资源文件中,并且您将只有一个图像副本存储在程序集的资源中。

    关于visual-studio - Visual Studio : How to store an image resource as an Embedded Resource?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/278838/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com