Access GIF frames with C#

Valeria picture Valeria · Feb 12, 2009 · Viewed 17.3k times · Source

I'm a beginner in C#. I would like to know if there's a way to access different frames inside a GIF animation with C#. I'm using Visual Studio 2008.

Answer

Renaud Bompuis picture Renaud Bompuis · Feb 12, 2009

Try this:

using System.Drawing;    
using System.Drawing.Imaging;

Image gifImg = Image.FromFile(pathToGifFile);
FrameDimension dimension = new FrameDimension(gifImg.FrameDimensionsList[0]);
// Number of frames
int frameCount = gifImg.GetFrameCount(dimension);
// Return an Image at a certain index
gifImg.SelectActiveFrame(dimension, index);