嵌入资源和添加图像

时间:2014-06-20 08:21:38

标签: image forms resources gtk

我正在使用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>);

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

1 个答案:

答案 0 :(得分:0)

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

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

这将资源文件作为Stream返回。

如果这有帮助,感谢that像我这样的人:)