Tag: embedded resource

如何读取可移植类库中的资源文件?

我有一个可移植的库,我用于Windows Phone应用程序。 在同一个可移植库中,我有几个内容文件( Build Action = Content )。 我在Portable Library中创建了一个类DataReader ,它应该向我返回一个流到内容文件。 但是,使用下面的代码,我一直从GetManifestResourceStream返回null 。 我究竟做错了什么? public class DataReader { public static Stream GetStream(string code) { string path = string.Format(“./data/code-{0}.dat”, code); return Assembly.GetExecutingAssembly().GetManifestResourceStream(path); } }

如何将嵌入式资源作为字节数组读取而不将其写入磁盘?

在我的应用程序中,我使用CodeDom.Compiler从source.cs文件编译另一个程序,并在编译时使用以下命令嵌入一些资源(exe和dll文件): // …. rest of code if (provider.Supports(GeneratorSupport.Resources)) { cp.EmbeddedResources.Add(“MyFile.exe”); } if (provider.Supports(GeneratorSupport.Resources)) { cp.EmbeddedResources.Add(“New.dll”); } // ….rest of code 在编译文件中,我需要将嵌入资源作为字节数组读取。 现在我通过使用下面的函数和使用将资源提取到磁盘来实现这一点 File.ReadAllBytes(“extractedfile.exe”); File.ReadAllBytes(“extracteddll.dll”); 我使用此函数将两个文件解压缩到磁盘后执行此操作: public static void ExtractSaveResource(String filename, String location) { // Assembly assembly = Assembly.GetExecutingAssembly(); System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); // Stream stream = assembly.GetManifestResourceStream(“Installer.Properties.mydll.dll”); // or whatever // string my_namespace = a.GetName().Name.ToString(); […]

如何检查图像对象是否与资源中的对象相同?

因此,我正在尝试创建一个简单的程序,只需在单击时更改图片框中的图片即可。 我目前只使用两张图片,所以我的图片框点击事件function的代码如下所示: private void pictureBox1_Click(object sender, EventArgs e) { if (pictureBox1.Image == Labirint.Properties.Resources.first) pictureBox1.Image = Labirint.Properties.Resources.reitmi; else if (pictureBox1.Image == Labirint.Properties.Resources.reitmi) pictureBox1.Image = Labirint.Properties.Resources.first; } 由于某种原因if语句不起作用,图片不会改变。 我该怎么办? 注意:原始代码包含第二个错误, if第一个条件的撤消效果将与Cyral的答案建议的修复一起使用,但添加else没有解决问题 – 单步执行代码仍显示没有匹配任何一个图像。 if (pictureBox1.Image == Labirint.Properties.Resources.first) pictureBox1.Image = Labirint.Properties.Resources.reitmi; if (pictureBox1.Image == Labirint.Properties.Resources.reitmi) // was missing else pictureBox1.Image = Labirint.Properties.Resources.first;