[Gtk-sharp-list] Getting frames from a GIF animation
Gustavo Rubio
gustavo at 42ideas.mx
Thu Apr 11 02:22:33 UTC 2013
Doug,
You might want to check the GDK namespace (GIMP Drawing Kit) and not GTK
itself, there is the concept of Pixbuf in GDK (which would be the
equivalent of GDI+ for Windows) that allows you to work on images.
There is a PixbufAnimationIter (
http://docs.go-mono.com/?link=T%3aGdk.PixbufAnimationIter) class that might
come handy, as I understand you'd have to create a new Gdk.PixbufAnimation
object and then get the Iter by inviking a method and then get the frames:
var animation = new Gdk.PixbufAnimation("path_to.gif");
var iter = animation.GetIter(start_time);
var pixbuf = iter.Pixbuf; //assign the frame
iter.Advance(time); //advance to next frame
var pixbuf2 = iter.Pixbuf; //here you'll get the second frame
I haven't tried yet this, but I'm pretty sure this is what you are after.
Let me know if it worked.
On Wed, Apr 10, 2013 at 6:58 PM, Doug Blank <doug.blank at gmail.com> wrote:
> I couldn't figure out how to access the data through Gtk#, so I got
> the data through System.Drawing:
>
> public static List loadPictures (string filename)
> {
> List list = new List();
> System.Drawing.Bitmap image =
> (System.Drawing.Bitmap)System.Drawing.Bitmap.FromFile(filename);
> System.Drawing.Imaging.FrameDimension dimension = new
>
> System.Drawing.Imaging.FrameDimension(image.FrameDimensionsList[0]);
> int frame_count = image.GetFrameCount(dimension);
> for (int i=0; i < frame_count; i++) {
> image.SelectActiveFrame(dimension, i);
> list.append( new Graphics.Picture(image));
> }
> return list;
> }
>
> -Doug
>
> On Wed, Apr 10, 2013 at 1:41 PM, Doug Blank <doug.blank at gmail.com> wrote:
> > Gtk-sharp List,
> >
> > I can use the Gtk# interface to get the frames of a gif animation
> > based on time, like the following IronPython code shows:
> >
> > image = Gtk.Image(filename)
> > if image.Animation:
> > if not image.Animation.IsStaticImage:
> > iter = image.Animation.GetIter(System.IntPtr.Zero)
> > while iter.DelayTime > -1:
> > pixbuf = iter.Pixbuf
> > ## do something with pixbuf
> > iter.Advance(System.IntPtr.Zero) ## advance to current time
> >
> > But, can I actually get the actual individual *frames* from the gif
> > file? That is, I can use this interface to step through time getting
> > the appropriate image for the specified time, but if an animated gif
> > has 7 gifs in it, is there a direct way to just get the 7 pixbufs?
> >
> > Thanks for any pointers,
> >
> > -Doug
> _______________________________________________
> Gtk-sharp-list maillist - Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
>
--
*Gustavo Rubio*
MX: (664) 608-0659
US: (619) 502-9192
http://42ideas.mx
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/gtk-sharp-list/attachments/20130410/06bd0b88/attachment.html>
More information about the Gtk-sharp-list
mailing list