我正在制作一个简单的FLTK应用程序(在Windows中),需要在FL_Window中显示PNG图像,从磁盘一个接一个地加载它们。我将此代码作为起点,但它不显示我可以确认的图像与可执行文件位于同一文件夹中:
int main(int argc, char **argv)
{
Fl_Window *main_window = NULL;
fl_register_images();
flw = new Fl_Window(1680,1050,title);
Fl_Shared_Image *a = Fl_Shared_Image::get("picture.png");
if (a != NULL)
{
cout << "Image loaded" << endl;
}
else
{
cout << "No image loaded" << endl; // <==== This is printed
}
flw->begin();
// add image to window code here, not sure what to write but
// image doesnt even load
flw->end();
main_window->show();
int fl_ret = Fl::run();
return fl_ret;
}
任何帮助都非常感谢..
答案 0 :(得分:4)
用于
的Fl_Shared_Image类“查找或加载可由多个小部件共享的图像。”
使用Fl_PNG_Image类
int main() {
fl_register_images();
Fl_Window win(720,486);
Fl_Box box(10,10,720-20,486-20);
Fl_PNG_Image png("picture.png");
box.image(png);
win.show();
return(Fl::run());
}