This is my code:
#include <gtk/gtk.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
void destroy(void) {
gtk_main_quit();
}
int main()
{
GdkPixbuf* buf;
GdkPixbuf* buf2;
GError* err = NULL;
int a=0, i=0, j=0;
GtkWidget* window;
GtkWidget *image =0;
gtk_init (NULL,NULL);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
buf = gdk_pixbuf_new_from_file("1.jpg", &err);
buf2 = gdk_pixbuf_new_from_file("2.jpg", &err);
for(i=0; i<10; i++)
{
if((i%2)==0)
{
gtk_image_set_from_pixbuf(GTK_IMAGE(image), buf);
for(j=0; j<10000; j++)
{}
}
else
{
gtk_image_set_from_pixbuf(GTK_IMAGE(image), buf2);
for(j=0; j<10000; j++)
{}
}
g_signal_connect(G_OBJECT (window), "destroy",
G_CALLBACK (destroy), NULL);
gtk_container_add(GTK_CONTAINER (window), image);
gtk_widget_show_all(window);
gtk_main();
}
return 0;
}
And this is the result:
(gtk:4783): Gtk-CRITICAL **: gtk_image_set_from_pixbuf: assertion 'GTK_IS_IMAGE (image)' failed
(gtk:4783): Gtk-CRITICAL **: gtk_container_add: assertion 'GTK_IS_WIDGET (widget)' failed
^C
What I am trying to do is : I have 2 images, and a loop that I want to show one image for odd numbers and other image for even numbers. But this simple task seems very hard to do! please help me to correcting my code...thank you!