I wrote the post for extracting gif frame image from an animated gif image in Java - Java: Extract Gif Images From An Animated Gif Image.
In this post, I have tried to do same thing in C# as well :D
I picked up from the following source gif image from Wikipedia.
In this post, I have tried to do same thing in C# as well :D
Code
using System.Drawing; using System.Drawing.Imaging; namespace Utility { public class GifImageUtils { public static void SaveAnimatedGifFrames(string path, string outDir) { var gifImg = Image.FromFile(path); var dimension = new FrameDimension(gifImg.FrameDimensionsList[0]); int frameCount = gifImg.GetFrameCount(dimension); for (int i = 0; i < frameCount; i++) { gifImg.SelectActiveFrame(dimension, i); // create a frame image from the original source image - clone is mandatory var frame = (Image)gifImg.Clone(); frame.Save(outDir+"/"+i+".gif", ImageFormat.Gif); } } } }
Example Result
I will show you the example execution result of above code.I picked up from the following source gif image from Wikipedia.
"SmallFullColourGIF" by GDallimore - Own work. Licensed under Creative Commons Attribution-Share Alike 3.0 via Wikimedia Commons - http://commons.wikimedia.org/wiki/File:SmallFullColourGIF.gif#mediaviewer/File:SmallFullColourGIF.gif
Following Gif images are generated from the above C# source animated "SmallFullColourGIF".
コメント
Create Full Color Bitmap