【问题标题】:How to pack images to DLL in C#如何在 C# 中将图像打包到 DLL 中
【发布时间】:2015-11-02 03:09:53
【问题描述】:

我的类库的 View/Images 文件夹中有图像。我试图将它们的构建操作设置为资源和嵌入式资源,但它们没有打包到类库 dll 中。我该怎么做?

【问题讨论】:

  • WPF 中,您应该将构建操作设置为Resource
  • 理想情况下,IMO 针对此类情况的构建操作应该是内容。特别是图像。它们作为内容的加载速度比作为嵌入式资源的加载速度更快。

标签: c# .net wpf dll resources


【解决方案1】:

正如 Reza 所说,将所有图像的 Build 操作设置为 Embedded Resource。我使用以下代码 sn-p 检查图像是否已加载到 DLL 中。我能够获取所有图像

protected void btnGetImages_Click(object sender, EventArgs e)
        {
            Assembly currentAssembly = Assembly.GetExecutingAssembly();
            string[] resources = currentAssembly.GetManifestResourceNames();
            foreach(string resource in resources)
            {
                Response.Write(resource + "<br/>");
            }
        }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-12
    • 1970-01-01
    • 2020-08-31
    相关资源
    最近更新 更多