英文:
How to add an image in a Xforms interface in language C
问题
根据您提供的代码和问题描述,您遇到了一个问题,即编译时无法识别类型 FL_IMAGE
。可能的原因是您的代码缺少必要的库或头文件。您需要确保已正确包含与 Xforms 图像处理相关的头文件和库。
以下是可能的解决方案:
-
包含正确的头文件:请确保在您的代码中包含了与 Xforms 图像处理相关的头文件。通常情况下,您需要包含类似于
#include <forms.h>
的头文件。请检查您的包含语句,确保它们指向正确的头文件路径。 -
检查库依赖项:确保您的项目已正确链接 Xforms 库。在编译时,需要使用
-lforms
或类似的选项来链接 Xforms 库。请检查您的编译命令,以确保已包含所需的库。 -
确认支持图像加载:确保您的 Xforms 库支持图像加载。某些版本的 Xforms 可能不支持图像处理功能,或者可能需要额外的设置。请查看您所使用的 Xforms 版本的文档,以了解有关图像处理的更多信息。
-
查看错误消息:如果编译时出现错误消息,务必查看错误消息的详细信息,以找出问题所在。错误消息通常会提供有关缺少的头文件或库的提示。
请根据上述建议检查您的代码和编译设置,以解决 FL_IMAGE
未识别的问题。如果问题仍然存在,您可能需要查阅 Xforms 的文档或寻求相关支持来获取更多帮助。
英文:
I have to do an a GUI for a project and for better ergonomics i want to add images or pictures to it. For the project i have to do it in C or C++ and I'm using Xforms to create the GUI.
There is my code for the moment:
#include <stdio.h>
#include <forms.h>
#define WIDTH 800
#define LENGTH 480
FL_FORM *menu;
FL_IMAGE *skiold;
FL_OBJECT *lower_bar;
FL_OBJECT *deco;
/* ------------- */
/* main fonction */
/* ------------- */
int main(int argc, char *argv[])
{
fl_initialize(&argc, argv, 0, 0, 0);
menu = fl_bgn_form(FL_FLAT_BOX, WIDTH, LENGTH);
fl_set_form_background_color(menu, FL_WHITE);
lower_bar = fl_add_box(FL_FLAT_BOX, 0, 400, 800, 80, "");
fl_set_object_color(lower_bar, FL_DARKER_COL1, FL_DARKER_COL1);
deco = fl_add_text(FL_NORMAL_TEXT, 250, 420, 300, 50, "PRINCIPAL MENU");
fl_set_object_lsize(deco, 30);
fl_set_object_color(deco, FL_DARKER_COL1, FL_DARKER_COL1);
/*skiold = flimage_load("logo_skiold.png")*/
fl_end_form();
fl_show_form(menu, FL_PLACE_MOUSE, FL_FULLBORDER, "Emulateur");
fl_do_forms();
fl_hide_form(menu);
fl_finish();
return 0;
}
From what I saw in the documentation, I just had to create a variable of type FL_IMAGE and load it after. But when I compile it, it returns that it doesn't recognize the type FL_IMAGE.
So, I don't know if this is a problem of libraries, if there are others methods or if this is just impossible.
答案1
得分: 1
以下是翻译好的部分:
"INSTALL" 文档文件中指出,要构建 libflimage 及其头文件,您必须以 root 身份配置、编译并安装:
然后您将获得一个 libflimage.so 和一个 flimage.h 供包含使用。
注意:我尚未使用您的源代码进行完全测试,只完成了构建/安装,并获得了 libflimage.so 和 flimage.h。
补充说明
现在我测试了一切都正常,图像已显示,但需要一个画布:
// gcc prova.c -lforms -lflimage -o prova
#include <stdio.h>
#include <forms.h>
#include <flimage.h>
#define WIDTH 800
#define LENGTH 480
FL_FORM *menu;
FL_IMAGE *skiold;
FL_OBJECT *lower_bar;
FL_OBJECT *deco;
FL_OBJECT *canv;
/* ------------- */
/* 主函数 */
/* ------------- */
int main(int argc, char *argv[])
{
fl_initialize(&argc, argv, 0, 0, 0);
menu = fl_bgn_form(FL_FLAT_BOX, WIDTH, LENGTH);
fl_set_form_background_color(menu, FL_WHITE);
canv = fl_add_canvas(FL_NORMAL_CANVAS, 0, 0, 100, 100, "");
lower_bar = fl_add_box(FL_FLAT_BOX, 0, 400, 800, 80, "");
fl_set_object_color(lower_bar, FL_DARKER_COL1, FL_DARKER_COL1);
deco = fl_add_text(FL_NORMAL_TEXT, 250, 420, 300, 50, "PRINCIPAL MENU");
fl_set_object_lsize(deco, 30);
fl_set_object_color(deco, FL_DARKER_COL1, FL_DARKER_COL1);
flimage_enable_png();
// skiold = flimage_load("logo_skiold.png")
skiold = flimage_load("/path/to/mypng/mypng.png");
fl_end_form();
fl_show_form(menu, FL_PLACE_MOUSE, FL_FULLBORDER, "Emulateur");
flimage_display(skiold, FL_ObjWin(canv));
fl_do_forms();
fl_hide_form(menu);
fl_finish();
return 0;
}
英文:
The INSTALL doc file states that for building libflimage and its headers you must configure and make and make install as root.
Then you have also a libflimage.so and an flimage.h to include.
Note: I've noy yet tested all this with your source. I've only done the build/install and got also libflimage.so and an flimage.h available
ADDENDUM
Now I testes ad all is Ok, the image is displayed but a canvas is needed:
// gcc prova.c -lforms -lflimage -o prova
#include <stdio.h>
#include <forms.h>
#include <flimage.h>
#define WIDTH 800
#define LENGTH 480
FL_FORM *menu;
FL_IMAGE *skiold;
FL_OBJECT *lower_bar;
FL_OBJECT *deco;
FL_OBJECT *canv;
/* ------------- */
/* main fonction */
/* ------------- */
int main(int argc, char *argv[])
{
fl_initialize(&argc, argv, 0, 0, 0);
menu = fl_bgn_form(FL_FLAT_BOX, WIDTH, LENGTH);
fl_set_form_background_color(menu, FL_WHITE);
canv = fl_add_canvas(FL_NORMAL_CANVAS, 0, 0, 100, 100,"");
lower_bar = fl_add_box(FL_FLAT_BOX, 0, 400, 800, 80, "");
fl_set_object_color(lower_bar, FL_DARKER_COL1, FL_DARKER_COL1);
deco = fl_add_text(FL_NORMAL_TEXT, 250, 420, 300, 50, "PRINCIPAL MENU");
fl_set_object_lsize(deco, 30);
fl_set_object_color(deco, FL_DARKER_COL1, FL_DARKER_COL1);
flimage_enable_png();
//skiold = flimage_load("logo_skiold.png")
skiold = flimage_load("/path/to/mypng/mypng.png");
fl_end_form();
fl_show_form(menu, FL_PLACE_MOUSE, FL_FULLBORDER, "Emulateur");
flimage_display(skiold, FL_ObjWin(canv));
fl_do_forms();
fl_hide_form(menu);
fl_finish();
return 0;
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论