views:

416

answers:

3

I keep getting a broken image (a red 'X' in a paper, it doesn't even start loading the one i want, I don't know if this is clear enough) and don't know why, here is what i tried:

image = gtk_image_new_from_file("abc.png");
gtk_container_add (GTK_CONTAINER (window), image);
gtk_widget_show (image);
gtk_widget_show (window);`

I am a newbie in GUI programming so please be nice! haha

I forgot to say that this is under windows

UPDATE: noticed that the error is in "gdk_pixbuf_new_from_file" it returns me the error value, can't solve the problem yet

if i run the debugger, it says "Error loading file: #4 Failed to open file 'abc.jpeg': No such file or directory", it should be in the folder where the executable is? anyway if i put the complete path it doesn't find it either

A: 

Check if you have GdkPixbuf image loader modules. Usually they are in lib/gtk-2.0/2.10.0/loaders/ directory. You should see some libpixbufloader-bmp.dll files, one for each supported image format.

You could also try to load image using:

GError *error = NULL;
GdkPixbuf *pix = gdk_pixbuf_new_from_file ("abc.png", &error);
if (pix == NULL) {
    g_printerr ("Error loading file: #%d %s\n", error->code, error->message);
    g_error_free (error);
    exit (1);
}
GtkWidget *widget = gtk_image_new_from_pixbuf (pix);

so that you can get more error information.

el.pescado
"Process terminated with status 1 (0 minutes, 0 seconds)" there has to be some kind of error that make gdk_pixbuf_new_from_file return NULL.
Machuk
A: 

Glib/Gtk are quite verbose with errors to stdout/stderr, is there nothing there? Run the program under "strace -eopen" to see what files it's trying to open? Are you absolutely sure the image is present and readable by the process?

Andy Ross
+1  A: 

I had the same problem (on some machines) then I compiled an application for Windows using a recent version of GTK+. In older versions of GTK+, or gdk-pixbuf to be exact, each image loading plugin supplied a set of magic patterns to identify the file format(s) if can load. But then glib got an API for identifying files gdk-pixbuf was updated to use this instead. On Windows glib relies on the system for identifying files, but this is there it often fails. GTK+ doesn't find out what kind of file it is, and assumes there is no loader available for it. This, however, generates an error message in the lines of "no loader available" or at least "image could not be loaded". But maybe that's what you get then you supply the whole path?

I solved the problem by identifying the file types myself (using code from PCManFM) and loading the image with the type explicetly specified, using gdk_pixbuf_loader_new_with_mime_type(). A little cumbersome but it got the job done.

Grim
thank you, this was for a college proyect, but i already finished it. I ended working on linux, it worked the first time i tried, but it was a little dificult to install the SO and all the necesary packages since i never used it before.
Machuk