Portál AbcLinuxu, 5. května 2025 09:03
image1 = create_pixmap (main_window, "000.png");
gtk_widget_show (image1);
avsak kdyz jsem program zkomiloval, obrazek se nezobrazil a vypsalo to chybu:
** WARNING **: Couldn't find pixmap file: 000.png
poradi nekdo? dekuju
Jinak ta chybicka se opravdu objevila pri kompilaci ??
1. Co je to za funkcia create_pixmap? v dokumentacii gtk+ som to nenasiel 2.Mas gtk+ skompilovane s podporou png ? 3. A co absolutna cesta create_pixmap (main_window, "/home/user/000.png"); 4.GtkPixmap has been deprecated since GTK+ 2.0 and should not be used in newly written code. Use GtkImage instead. Teda funkcie GtkPixmap uz nie su podporovane http://library.gnome.org/devel/gtk/2.13/GtkPixmap.html
#ifdef HAVE_CONFIG_H # include "config.h" #endif #include "sys/types.h" #include "sys/stat.h" #include "unistd.h" #include "string.h" #include "stdio.h" #include "gtk/gtk.h" void add_pixmap_directory (const gchar *directory); GtkWidget* create_pixmap (GtkWidget *widget, const gchar *filename); static GList *pixmaps_directories = NULL; /* Use this function to set the directory containing installed pixmaps. */ void add_pixmap_directory (const gchar *directory) { pixmaps_directories = g_list_prepend (pixmaps_directories, g_strdup (directory)); } /* This is an internally used function to find pixmap files. */ static gchar* find_pixmap_file (const gchar *filename) { GList *elem; elem = pixmaps_directories; while (elem) { gchar *pathname = g_strdup_printf ("%s%s%s", (gchar*)elem->data, G_DIR_SEPARATOR_S, filename); if (g_file_test (pathname, G_FILE_TEST_EXISTS)) return pathname; g_free (pathname); elem = elem->next; } return NULL; } /* This is an internally used function to create pixmaps. */ GtkWidget* create_pixmap (GtkWidget *widget, const gchar *filename) { gchar *pathname = NULL; GtkWidget *pixmap; if (!filename || !filename[0]) return gtk_image_new (); pathname = find_pixmap_file (filename); if (!pathname) { g_warning ("Couldn't find pixmap file: %s", filename); return gtk_image_new (); } pixmap = gtk_image_new_from_file (pathname); g_free (pathname); return pixmap; } int main (int argc, char *argv[]) { GtkWidget *window1; GtkWidget *fixed1; GtkWidget *image1; gtk_set_locale (); gtk_init (&argc, &argv); add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps"); window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window1), "window1"); fixed1 = gtk_fixed_new (); gtk_widget_show (fixed1); gtk_container_add (GTK_CONTAINER (window1), fixed1); image1 = create_pixmap (window1, "logo.png"); gtk_widget_show (image1); gtk_fixed_put (GTK_FIXED (fixed1), image1, 88, 96); gtk_widget_set_size_request (image1, 216, 72); gtk_widget_show (window1); gtk_main (); return 0; }
add_pixmap_directory (PACKAGE_DATA_DIR "/" PACKAGE "/pixmaps");Pri testovaní je možné tam pridať aj ďalší adresár (napr. "./pixmaps" ...).
add_pixmap_directory (".");(ale normálne nainštalovaný program by asi mal mať obrázky v /usr/share/nieco alebo /usr/local/share/nieco) Inak ja by som tam ešte pridal
g_signal_connect(window1, "delete_event", G_CALLBACK(gtk_main_quit), NULL);(aby sa ten program dal jednoduchšie ukončiť).
image1 = g_object_new(GTK_TYPE_IMAGE, "file", "000.png", NULL);
#include "gtk/gtk.h" int main (int argc, char *argv[]) { GtkWidget *window1; GtkWidget *fixed1; GtkWidget *image1; gtk_set_locale (); gtk_init (&argc, &argv); window1 = gtk_window_new (GTK_WINDOW_TOPLEVEL); gtk_window_set_title (GTK_WINDOW (window1), "window1"); fixed1 = gtk_fixed_new (); gtk_widget_show (fixed1); gtk_container_add (GTK_CONTAINER (window1), fixed1); image1 = g_object_new(GTK_TYPE_IMAGE, "file", "000.png", NULL); gtk_fixed_put (GTK_FIXED (fixed1), image1, 50, 50); gtk_widget_set_size_request (image1, 216, 72); gtk_widget_show (image1); gtk_widget_show (window1); gtk_main (); return 0; }
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.