Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将图像从嵌入式资源提取到临时文件夹,然后执行它?_C#_.net_Resources_Embedded Resource - Fatal编程技术网

C# 如何将图像从嵌入式资源提取到临时文件夹,然后执行它?

C# 如何将图像从嵌入式资源提取到临时文件夹,然后执行它?,c#,.net,resources,embedded-resource,C#,.net,Resources,Embedded Resource,我有一个应用程序,它从源文件编译另一个winform应用程序,并在运行时创建.resources文件,然后在编译时将.resources文件添加为嵌入式资源。。 我用于创建新的.resources文件的代码如下: // Creating .resources file from a file named Photo.jpg string myfile = "photo.jpg"; using (ResourceWriter rw = new ResourceW

我有一个应用程序,它从源文件编译另一个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?

此支持文章

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