SoFunction
Updated on 2025-03-06

Detailed explanation of how to obtain pictures in resource files by C# programming

Detailed explanation of how to obtain pictures in resource files by C# programming

This article mainly introduces the method of C# programming to obtain pictures in resource files, and involves relevant techniques for C#'s resource file operation in project for reference. The specific content is as follows:
example:

using System;
 
using ;
 
using ;
 
using ;
 
using ;
 
using ;
 
namespace CL
 
{
 
  public class RES
 
  {
 
    /// <summary>
 
    /// Define a resource file name Resource file name = The project's default namespace + file name (without extension) 
    /// </summary>
 
    private string PublicResourceFileName = "";
 
    /// <summary>
 
    /// Read a resource from the resource file 
    /// </summary>
 
    /// <param name="resFile">Resource file name namespace + file name</param> 
    /// <param name="resName">Resource name to read</param> 
    /// <returns>Returns a resourceReturns NULL if read failed</returns> 
    public  ReadFromResourceFile(String resName)
 
    {
 
      try
 
      {
 
        Assembly myAssembly;
 
        myAssembly = ();
 
         rm = new
 
        (PublicResourceFileName, myAssembly);
 
        return (resName);
 
      }
 
      catch (Exception ex)
 
      {
 
        return null;
 
      }
 
    }
 
    /// &lt;summary&gt;
 
    /// Get resource pictures 
    /// &lt;/summary&gt;
 
    /// <param name="name">File name</param> 
    /// <returns>Resource Pictures</returns> 
    public Bitmap GetResourceImage(String name)
 
    {
 
      Object tempbitmap = null;
 
      tempbitmap = ReadFromResourceFile(name);
 
      if (().Equals(typeof(Bitmap)))
 
      {
 
        return (Bitmap)tempbitmap;
 
      }
 
      return null;
 
    }
 
  }
 
}
 
//Call the GetResourceImage method.  The name is the name of the file without a suffix.

Thank you for reading, I hope it can help you. Thank you for your support for this site!