我在C#中编写了一个项目,它使用了大量的图像,Milk模型和openGL,我想将所有内容打包在一个exe中,这样我就可以将它上传到我的网站了.现在我得到了一个依赖于jpgs等其他文件的exe.我尝试过使用ILMerge但无法使用它.有更简单的解决方案吗?谢谢.
将其添加为嵌入式资源.
在Visual Studio中:
你将在exe内部拥有该图像.稍后您可以使用Reflection并在运行应用程序时获取图像.
=========从应用程序中获取嵌入式图像=========
首先解决第一个问题:将图像作为嵌入资源.
第二个问题:使用Reflection访问图像:
private void Form1_Load(System.Object sender, System.EventArgs e)
{
System.Reflection.Assembly myAssembly = System.Reflection.Assembly.GetExecutingAssembly();
Stream myStream = myAssembly.GetManifestResourceStream("EmbeddingExample.image1.bmp");
Bitmap image = new Bitmap(myStream);
this.ClientSize = new Size(image.Width, image.Height);
PictureBox pb = new PictureBox();
pb.Image = image;
pb.Dock = DockStyle.Fill;
this.Controls.Add(pb);
}
Run Code Online (Sandbox Code Playgroud)
从这里借来的源代码:
| 归档时间: |
|
| 查看次数: |
23452 次 |
| 最近记录: |