I am trying to extract the individual frames of an animated gif in my c# programm.
It creates a png for each frame - that works just fine, however they are just a bunch of copies of the first frame. What did I do wrong?
Image img = Image.FromFile(path);
FrameDimension dimension = new FrameDimension(img.FrameDimensionsList[0]);
int frameCount = img.GetFrameCount(dimension);
MemoryStream memory = new MemoryStream();
for(int i = 0; i < frameCount; i++){
img.SelectActiveFrame(dimension, i);
((Image)img.Clone).Save(memory, System.Drawing.Imaging.ImageFormat.Png);
File.WriteAllBytes(myFolder + "/frame_"+i+".png", memory.ToArray());
}
Update:
After some tinkering I found out that it works, if use this:
Bitmap bmp = new Bitmap(img);
bmp.Save(Application.dataPath + projectFolder.Substring(6) + "/frame_"+i+".png");
Can somebody please explain to me, why this works and the original code does not?
Thank you very much!