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

RE: How can I show an animate GIF?



> I can load a normal GIF with
> "pixbuf = gdk_pixbuf_new_from_file("test.gif", &err);"
> and show it in a GTK-Drawing-Area. But then an animate
> GIF is shown but not animated
> Now I want to show an animate GIF in a
> GTK-Drawing-Area. Is this possible?
> Which commands are needed?
> 

Yes this should be possible.

You probably want to have a function similar to below to load the animation
first:

	GdkPixbufAnimation *animation_new_from_file(const gchar *filename)
	{
	    GdkPixbufAnimation *pba = NULL;
	    GError *error = NULL;
	
	    if(filename == NULL || strlen(filename) < 1)
	    {
		g_warning("%s: filename was NULL", __FUNCTION__);
		return NULL;
	    }
	    else
		g_message("%s: opening file:'%s'", __FUNCTION__, filename);
	
	    pba = gdk_pixbuf_animation_new_from_file(filename, &error);
	
	    if(pba == NULL)
	    {
		g_warning("%s: error loading file:'%s'", __FUNCTION__,
filename);
		
		/* look at error */
		if(error != NULL)
		  {
		    g_warning("%s: error domain:'%s', code:%d,
message:'%s'", 
			      __FUNCTION__,
g_quark_to_string(error->domain), error->code, error->message);
	
		    g_error_free(error);
		  }
		
		return NULL;
	    }

	    /* NOTE: this has a refcount of 1 it needs to be unref'd */
	    return pba;
	}

This will give you the animation.  If nomally you would use something like
gtk_image_set_from_animation(...) but because you want to use it in a
drawable, you will proabably want to use functions from:
http://developer.gnome.org/doc/API/2.0/gdk-pixbuf/gdk-pixbuf-animation.html

and gdk_draw_pixbuf() found here:
http://developer.gnome.org/doc/API/2.0/gdk/gdk-Drawing-Primitives.html#gdk-d
raw-pixbuf

I would suggest you use gdk_pixbuf_animation_get_iter() to get the first
iter of the starting frame of the animation, then use
gdk_pixbuf_animation_iter_get_delay_time() and set a timeout using
g_timeout_add() for the frame delay.  

On the callback from that, you can then use
gdk_pixbuf_animation_iter_get_pixbuf() to get the pixbuf for that frame.  

Once you have the pixbuf you can use gdk_draw_pixbuf() to put the animation
in the drawing area.



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