日期:2014-05-18  浏览次数:21067 次

资源文件如何打包才能不放到exe里面
主程序21m,图片放到资源文件里面,光图片就有19m,请问怎么才能分离图片?

------解决方案--------------------
不要将图片的生成操作设为嵌入的资源,这样图片就会存放在exe所在的resourse文件夹下。
------解决方案--------------------
可能只能用代码加载,不然的话就打包到exe文件里面了
------解决方案--------------------
设置资源文件的 Build Action 属性
------解决方案--------------------
C# code
    
添加一个Resource1.resx文件,然后使用“添加资源”--》“添加现在文件”
我这里把系统自带的Notepad.exe加了进来
  
       private bool WriteFile(byte[] pReadByte, string FileName)
        {
            FileStream fs = null;
            try
            {
                fs = new FileStream(FileName, FileMode.OpenOrCreate);
                fs.Write(pReadByte, 0, pReadByte.Length);
            }
            catch(Exception ex)         
            {
                MessageBox.Show(ex.Message);
                return false;
            }
            finally
            {
                if (fs != null)
                    fs.Close();

            }
            return true;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            System.Reflection.Assembly myAssembly;
            myAssembly = this.GetType().Assembly;

            //WindowsApplication1.Resource1 得修改成你的工程名称.资源文件名称
            System.Resources.ResourceManager myManager = new System.Resources.ResourceManager("WindowsApplication1.Resource1", myAssembly);

            try
            {
                byte[] byteNotepad = (byte[])myManager.GetObject("notepad");
                WriteFile(byteNotepad, @"d:\\Notepad.exe");
                System.Diagnostics.Process.Start(@"d:\\Notepad.exe");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }           
        }

------解决方案--------------------
增加资源后,可以在Resource1.Designer.cs生成相对应的方法,也可以直接使用这些方法
谁可以试试啊