1. 程式人生 > >從dll中呼叫嵌入的資原始檔

從dll中呼叫嵌入的資原始檔

Resource.dll原始碼

using System;
using System.Collections.Generic;
using System.Text;

namespace Resource
{
    public class ResourceDll
    {
        public ResourceDll()
        {
           
        }

        public System.IO.Stream ReturnStream(string strImageName)
        {
            return this.GetType().Assembly.GetManifestResourceStream(strImageName);
        }
    }

=========================================================================

呼叫的部分程式碼

...

using Resource;

...

private ResourceDll resDll;
        public Form1()
        {
            InitializeComponent();
            img = new Bitmap("mediaPlayer.jpg");
            resDll = new ResourceDll();
            picBoxPlay.Image = Bitmap.FromStream(resDll.ReturnStream("Resource.Circle.jpg"));
            picBoxStop.Image = Bitmap.FromStream(resDll.ReturnStream("Resource.StopButNormal.jpg"));
            picBoxList.Image = Bitmap.FromStream(resDll.ReturnStream("Resource.buttonNormal.jpg"));
            s = new Sound();
        }

注:資原始檔名稱"Resource.Circle.jpg"的解釋:Dll名稱.檔案明;資原始檔名稱可通過Reflector檢視Resource.dll驗證。