## Wednesday, January 21, 2009

### FLTK2 howto: Display images on widgets

I spent some time figuring out how to do this. Yes, you simply call:

widgetName->image(myPrettyImage);

But (at least for me) this did not work.
So I searched in the documentation but all seemed right.
The next logical step was "search on Google" (everyone should know that "he is your friend").

I read something on a forum regarding the function fltk::register_images() (Absolutely not documented) and I understood that it must be called before you use any other image-related stuff with fltk2.

So, if you want a widget to display your beautiful image you must code a main() like this:

#include "myMainWindowWithBackgrounImage.h"#include <fltk/SharedImage.h>#include <fltk/run.h>int main(){    fltk::register_images();    myMainWindowWithBackgroundImage win;    win.show();    return fltk::run();}
You must then link the executable to libpng, libjpeg and libfltk2_images passing "-lpng -ljpeg -lfltk2_images" to the compiler.