Re: Show a JPG-Image in a GTK-Window with GTK 2



Christian Schneider wrote:

Hallo,

someone gave me the advise to load a JPG in a window
with this Code:

////////////////////////////////////////////////////
GError *err = NULL;
GtkWindow *win;
GdkPixbuf *pixbuf;
GdkPixmap *pixmap;
g_type_init ();
pixbuf = gdk_pixbuf_new_from_file("test.JPG", &err);
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap,
NULL, 0);
g_object_unref(pixbuf);
/*53*/win = gtk_window_new (GTK_WINDOW_TOPLEVEL);

/*55*/gtk_widget_set_app_paintable(GTK_WIDGET(win),
GTK_TRUE);
gtk_widget_realize(GTK_WIDGET(win));
/*57*/gdk_window_set_back_pixmap(win->window, pixmap,
GTK_FALSE);
g_object_unref(pixmap);
////////////////////////////////////////////////////

If I compile this, I get the following Compileerror:
****************************************************
main.c:53: warning: assignment from incompatible
pointer type
main.c:55: `GTK_TRUE' undeclared (first use in this
function)
main.c:55: (Each undeclared identifier is reported
only once
main.c:55: for each function it appears in.)
main.c:57: structure has no member named `window'
main.c:57: `GTK_FALSE' undeclared (first use in this
function)
****************************************************
Where can I find GTK_TRUE and GTK_FALSE and use it or
is there an alternative for my problem?


If I use the following code only I will get an error
"Speicherzugriffsfehler" (Segmentation fault) after
compiling and testing my program. Why? And can you
give me a solution?:

////////////////////////////////////////////////////
GError *err = NULL;
GtkWindow *win;
GdkPixbuf *pixbuf;
GdkPixmap *pixmap;
 g_type_init ();
pixbuf = gdk_pixbuf_new_from_file("treffen.JPG",
&err); /*If I use ddd it is shown "
for pixbuf*/
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap,
NULL, 0); /*This ist the segmentation fault line shown
by ddd: "in gdk_rgb_set_min_colors () from
/usr/lib/libgdk-x11-2.0.so.0"*/
////////////////////////////////////////////////////

Can someone help me?
Bye
Christian Schneider

Hi

1.) You need gtk_init not g_type_init
2.) GTK_TRUE = TRUE and GTK_FALSE=FALSE

Bye
David




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]