C# 将图像添加到资源中的Base64编码图像流(resx)

C# 将图像添加到资源中的Base64编码图像流(resx),c#,.net,resources,C#,.net,Resources,我正在做一个老项目,更新它。程序的一部分有一个toolstrip,上面有许多按钮,每个按钮上都有一个图像。我发现图像存储在表单的resx中的Base64编码imagestream中,并按如下方式访问: System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1)); ... this.imageList1 = n

我正在做一个老项目,更新它。程序的一部分有一个toolstrip,上面有许多按钮,每个按钮上都有一个图像。我发现图像存储在表单的resx中的Base64编码imagestream中,并按如下方式访问:

System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Form1));
...
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
...
this.toolStrip1.ImageList = this.imageList1;
...
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
...
this.toolStripButton1.ImageIndex = 0;  //There are 41 images, so this can be between 0 and 40
我需要添加另一个带有新图像的按钮。如何将图像添加到此流

我不能使用设计器,因为它在我加载表单时就会崩溃(我相信是因为它使用了带有不安全代码的自定义组件)

我总是可以只添加一个与流分离的新图像资源,但这会使一个按钮不同,因此会产生一致性问题,导致以后的维护问题。所以我想知道是否有任何方法可以让我编辑imagestream。我可以访问原始的base64字符串,但我不知道从这里到哪里去。

  • 创建另一个表单
  • 添加ImageList组件
  • 添加任意图像以生成“imagestream”
  • 打开旧的resx并复制“value”元素
  • 打开新的resx并粘贴值元素
  • 打开新表单
  • 根据需要添加图像
  • 保存新表单
  • 打开新表单的resx文件
  • 复制值元素
  • 打开旧表单的resx文件
  • 粘贴新的值元素

我找到了一种使用代码的方法:

imageList1.Images.Add( NEWIMAGE );
ResXResourceWriter writer = new ResXResourceWriter("newresource.resx");
writer.AddResource("imageList1.ImageStream",imageList1.ImageStream);
writer.Generate();
writer.Close();
writer.Dispose();

代码将把更新后的ImageStream写入新的资源文件。然后,我可以将其复制到当前的资源文件。

我尝试过这样做,但VS2008现在将toolstripbutton图像存储为单独的资源图像。(而不是作为一个imagestream资源)尝试将ImageList复制到新表单,然后添加图像谢谢您的回答!不过,我在您更新的同时找到了一个代码解决方案。如果我想导出为图像,有人能告诉我图像将存储在哪里吗?可能吗?