嵌入资源和添加图像



我正在开发一个表单应用程序与monodevelop。我正在使用gtk#.

我需要添加一个图像到窗体中的小部件。我也试图使这个图像嵌入资源,以及之前,包括它的形式。

到目前为止我得到的是:

HBox CharacterPic = new HBox();
Image LegionnairePic = new Image('somehow load the embedded resource image here');
CharacterPic.PackStart (LegionnairePic);

在左侧的"解决方案"部分,我添加了。jpeg文件,并将其"构建操作"更改为"嵌入式资源"。但是,我不能像这样访问/加载它们到表单中:

Image LegionnairePic = new Image(<namespace>.<resource>);

如何将图像资源添加到表单?我添加资源是否正确?

我相信您必须使用以下方法访问嵌入的文件:

// string resource_id is the Resource ID of the file in the sidebar “Properties”
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(resource_id);

以流的形式返回资源文件。

如果有帮助,像我一样感谢那个人:)

最新更新