tags:

views:

18

answers:

1
+1  Q: 

GTK+ and GdkPixbuf

Hi all,

I think I've got an understanding problem of GTK. My simple application has a stream of images and I'd like to display them within my GTK Window. Up to now, it looks like this:

GdkPixbuf *pb = gdk_pixbuf_new_from_data(img2, GDK_COLORSPACE_RGB, 
                     FALSE, 24/3, 320, 240, 320*3,
                     NULL, NULL);
if(pb == NULL)
    fprintf(stderr, "Pixbuf is null!\n");

if(image != NULL)
    gtk_container_remove(GTK_CONTAINER(window), image);
image = gtk_image_new_from_pixbuf(pb);
gtk_container_add(GTK_CONTAINER(window), image);

printf("Updated!\n");

img2 is my (rgb) buffer that gets updated from a stream each time. I guess gtk_container_remove and gtk_container_add might be stupid to use for this?

Here's what I've got in addition:

GtkWidget *window;
GtkWidget *image;

gtk_init(&argc, &argv);

window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

gtk_signal_connect(GTK_OBJECT(window), "destroy",
           GTK_SIGNAL_FUNC(destroy), NULL);

    /* ... */
    start_routine_for_stream_that_calls_the_above(...)
    /* ... */

gtk_widget_show_all(window);
gtk_main();

My problem is that it's not working this way... either I see only the last GdkPixbuf image or I see none, which is the correct behaviour ...

But how do I manage it to show an (stream of) updated GdkPixbuf?

Thanks for help

A: 

You need to be running the main loop while you change the images. For instance, you can do gtk_main() and use g_timeout_add() to schedule your callback to run say every second and replace images within that callback.

doublep
Ahh okay thx, I will have a look at it.. and what do you think of the gtk_container_remove and gtk_container_add? Is that a proper way?
Daniel
@Daniel: Yes, looks correct to me.
doublep
Cool, thanks :)
Daniel
@Daniel: However, there is `gtk_image_set_from_pixbuf()` function. Reusing the same `GtkImage` should be easier.
doublep
Awesome, it's working :) Big thanks for this!
Daniel