1

I am making a simple FLTK application (in windows) that needs to display PNG images in FL_Window, load them one after the other from disk. I have this code as a starting point but its not displaying the image which I can confirm is in the same folder as the executable:

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; } 

Any help greatly appreciated ..

1
  • Just a hint: please post complete and error-free code (as far as possible) if you're asking for help so others can compile and test your code. Your code is incomplete (no header include's) and has errors (there's no declaration for flw, main_window is assigned NULL, but finally there's main_window->show();. That said, you got good answers anyway, I can't add much to the answers below. Commented Jan 28, 2023 at 18:53

2 Answers 2

5

Fl_Shared_Image class used for

"Find or load an image that can be shared by multiple widgets."

use Fl_PNG_Image class

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()); } 
Sign up to request clarification or add additional context in comments.

Comments

1

You only loaded the image. Birol's answer loaded and displayed box.image(png); the image. If you are using an IDE, your IDE might be running an executable in another directory. Give the absolute address of your image, and it should work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.