Problem with Displaying Image using FLTK 1.3.5 on Raspberry Pi 4 B

31 views
Skip to first unread message

Dave Branson

unread,
Oct 29, 2020, 12:09:18 PM10/29/20
to fltk.general
I'm attempting to display a logo on the screen of my Pi.  When I run the C++ code below I get the window with it's label to display, but not the JPEG image.  The code compiled and linked, and the image resides in the same directory as the code.  Any advice would be appreciated.

// Display Image test

#include <FL/Fl.H>
#include <FL/Fl_Window.H>
#include <FL/Fl_Button.H>
#include <FL/Fl_Box.H>
#include <FL/Fl_JPEG_Image.H>

// Global pointers for the GUI objects
Fl_Window *mywindow;
Fl_Box *mypicturebox;
Fl_JPEG_Image *logo;


// Callback function
void mybutton_cb(Fl_Widget * w, long int data)
{
if (data == 1) {
mypicturebox->image(logo);
mypicturebox->redraw();
}
}
int main()
{
// The main window
mywindow = new Fl_Window(480, 320, "Display Logo");

// Load the image
logo = new Fl_JPEG_Image("logo.jpg");

// Provide a box for the image
mypicturebox = new Fl_Box(16, 20, 320, 160);
mypicturebox->image(logo);

// Make the window visible
mywindow->end();
mywindow->show();
return Fl::run();
}

Greg Ercolano

unread,
Oct 29, 2020, 12:39:47 PM10/29/20
to fltkg...@googlegroups.com
On 2020-10-29 08:57, Dave Branson wrote:
I'm attempting to display a logo on the screen of my Pi.  When I run the C++ code below I get the window with it's label to display, but not the JPEG image.  The code compiled and linked, and the image resides in the same directory as the code.  Any advice would be appreciated.

     Try supplying the absolute path to the image, e.g.

// Load the image
logo = new Fl_JPEG_Image("/some/absolute/path/logo.jpg");

    Also, add some error checking to the jpg file loading process; it might be saying the file
    couldn't be opened for some reason.. see the error checking example on this page.


Brian Tilley

unread,
Oct 29, 2020, 3:05:08 PM10/29/20
to fltkg...@googlegroups.com
Wouldn’t it be easier to use the getcwd() call to get the path to the folder in which the program was started?
The program may not be installed in the same folder by another user. 




--
You received this message because you are subscribed to the Google Groups "fltk.general" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fltkgeneral...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fltkgeneral/77c2fbe1-76da-27c7-58db-c3d419dc4c9e%40seriss.com.

Greg Ercolano

unread,
Oct 29, 2020, 3:51:32 PM10/29/20
to fltkg...@googlegroups.com
On 2020-10-29 12:04, 'Brian Tilley' via fltk.general wrote:
Wouldn’t it be easier to use the getcwd() call to get the path to the folder in which the program was started?
The program may not be installed in the same folder by another user. 

    Hmm, I'm not sure I know how getcwd() will help here.
    getcwd() will just return the path to the current directory, not necessarily where the .jpg is located.

Ian MacArthur

unread,
Oct 29, 2020, 5:24:21 PM10/29/20
to fltkg...@googlegroups.com
On 29 Oct 2020, at 19:04, 'Brian Tilley' wrote:


On Thu, 29 Oct 2020 at 16:39, Greg Ercolano wrote:
On 2020-10-29 08:57, Dave Branson wrote:
I'm attempting to display a logo on the screen of my Pi.  When I run the C++ code below I get the window with it's label to display, but not the JPEG image.  The code compiled and linked, and the image resides in the same directory as the code.  Any advice would be appreciated.

     Try supplying the absolute path to the image, e.g.

// Load the image
logo = new Fl_JPEG_Image("/some/absolute/path/logo.jpg");

    Also, add some error checking to the jpg file loading process; it might be saying the file
    couldn't be opened for some reason.. see the error checking example on this page.

Wouldn’t it be easier to use the getcwd() call to get the path to the folder in which the program was started?
The program may not be installed in the same folder by another user. 



Hi Brian,

Been a while - how’s the lockdown working out for you folks...?

Anyway: no, getcwd() probably will not help here. On Linux/X11 based systems, like a Pi, if you launch the process from the command line the process *usually* inherits the cwd of the shell it was launched from, which may well not be the directory in which the executable resides.

Worse, the various X11 Window Managers have a range of different, “interesting”, ideas about what cwd to pass to the processes they spawn when you click on an icon, so that even if you figure out something that works for you, it might not work for someone using a different WM.

(MS) Windows is simpler, as processes generally inherit their own directory as cwd at start.
OSX does something weird that I can’t recall now, but if you put things in a bundle that makes that work out better anyway...

At some point in the past, I posted some code that works (cross platform) to fetch the “home” directory for the executable file (which I needed to solve this exact issue...) but I don’t seem to have it now.

Oh, no, hold on: here we go (attached.)

get_app_path.c
get_app_path.h

Dave Branson

unread,
Oct 29, 2020, 6:37:19 PM10/29/20
to fltk.general
Thanks for the help - the absolute directory path worked.  I like the idea of using get_app_path to grab the actual path to the image, but the location is going to be static in this use case.
Reply all
Reply to author
Forward
0 new messages