C# 如何打开图像并将其保存到资源

C# 如何打开图像并将其保存到资源,c#,resources,openfiledialog,C#,Resources,Openfiledialog,我所拥有的是当用户单击一个按钮时,它会打开一个OpenFileDialog,当他打开一个图像时,我希望将其保存在参考资料中。我该怎么做 private void btnAddObject_Click(object sender, EventArgs e) { OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog(); fileDialog.Filter = &quo

我所拥有的是当用户单击一个按钮时,它会打开一个OpenFileDialog,当他打开一个图像时,我希望将其保存在参考资料中。我该怎么做

    private void btnAddObject_Click(object sender, EventArgs e)
    {
        OpenFileDialog fileDialog = new System.Windows.Forms.OpenFileDialog();

        fileDialog.Filter = "Image files (*.png) | *.png";

        fileDialog.ShowDialog();

        if(fileDialog.ShowDialog() == DialogResult.OK)
        {
            ResXResourceWriter.AddResource(fileDialog.FileName, );
            
        }
    }

代码取自

嗯,我确信这是可行的,但我试图做的是在现有资源中添加一个资源映像
using System;  
using System.Collections.Generic;  
using System.Text;  
using System.Resources;  
using System.Drawing;  
  
class Program  
{  
  static void Main(string[] args)  
  {  
    ResXResourceWriter rw = new ResXResourceWriter("Demo.resx");  
    using (Image image = Image.FromFile("logo.gif"))  
    {  
      rw.AddResource("WroxLogo", image);  
      rw.Close();        
    }  
  }  
}