【问题标题】:How to extract an image from embedded resources to temp folder then execute it?如何从嵌入式资源中提取图像到临时文件夹然后执行它?
【发布时间】:2012-05-02 05:35:55
【问题描述】:

我有一个应用程序,它从源文件编译另一个 winform 应用程序并在运行时创建一个 .resources 文件,然后在编译时将 .resources 文件添加为嵌入式资源。 我用于创建新的.resources 文件的代码如下:

 // Creating .resources file from a file named Photo.jpg

        string myfile = "photo.jpg";
        using (ResourceWriter rw = new ResourceWriter(@".\photoRes.resources"))
         {
           rw.AddResource("MyPhoto",File.ReadAllBytes(myfile));
         }

然后这个资源文件将作为嵌入式资源添加到编译的程序中。下面的行将完成这项工作

        // -- -- -- inside the CompileExecutable() function -- -- --
         CompilerParameters cp = new CompilerParameters();
         ..
         ..
         if (provider.Supports(GeneratorSupport.Resources))
            {
                cp.EmbeddedResources.Add("bindedfile.resources");
            }
         .. 
         ..

到目前为止,一切正常,我们从源文件编译的编译程序将是(程序大小+图片大小)。

图片现在是该文件的嵌入资源。所以为了访问图片,提取并执行它,需要在该文件的源代码中添加一些代码行,对吗?

我的问题是应该在source.cs 文件中写入什么来告诉它提取作为嵌入资源的图像,然后从临时文件夹中执行它。

当我将下面的行添加到 source.cs 时

string[] arrayofstrings = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceNames();
        foreach(string s in arrayofstrings) {MessageBox.Show(s);}

它显示了一个带有此文本的消息框:photoRes.resources

如何读取嵌入资源并将图像提取到临时文件夹然后执行?哪些行要添加到 source.cs 中?

【问题讨论】:

    标签: c# .net resources embedded-resource


    【解决方案1】:

    此支持文章How to embed and access resources by using Visual C#

    _imageStream = _assembly.GetManifestResourceStream("MyNameSpace.MyImage.bmp");
    

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 1970-01-01
      • 2017-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-22
      • 1970-01-01
      • 2013-04-04
      相关资源
      最近更新 更多