【问题标题】:How to open and save image to resources如何打开图像并将其保存到资源
【发布时间】:2021-08-22 16:27:17
【问题描述】:

我所拥有的是当用户单击一个按钮时,它会打开一个 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, );
            
        }
    }

【问题讨论】:

    标签: c# resources openfiledialog


    【解决方案1】:
    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();        
        }  
      }  
    }  
    

    代码取自http://www.navioo.com/csharp/source_code/Add_image_Resource_313.html

    【讨论】:

    • 嗯,我确信这可行,但我想做的是向我现有的资源添加资源图像
    猜你喜欢
    • 2018-04-03
    • 1970-01-01
    • 2013-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-11
    相关资源
    最近更新 更多