Reputation: 1219
All the codes I've found give me the same result: a bunch of exact looking frames. Meaning: it gives me a list of the first frame, repeated X number of times. The .gif I'm using has 30 frames, so I get 30 times the first frame, instead of the 30 different frames.
public static Image[] GetFramesFromAnimatedGIF(Image IMG)
{
List<Image> IMGs = new List<Image>();
int Length = IMG.GetFrameCount(FrameDimension.Time);
for (int i = 0; i < Length; i++)
{
IMG.SelectActiveFrame(FrameDimension.Time, i);
IMGs.Add(IMG);
}
return IMGs.ToArray();
}
What am I missing? ALL the codes I've looked give the first frame repeated X numbers of times.
This is what is supposed to look (using a webpage). See how each frame is different?
This is what it looks for me after saving every frame inside that array on a folder location (a bunch of equal frames):
P.S.: Yes, it's a .gif the image I'm using.
Update: The problem seems to be when I read the file in the OpenFileDialog, as it works if I pass my .gif by code. So how do I read an animated gif in the OpenFileDialong? Thank you.
Upvotes: 6
Views: 4399
Reputation: 941407
IMGs.Add(IMG);
That's the bug, you are adding the same IMG object over and over again. You need to make a deep copy of the frame. That's very easy to do:
IMGs.Add(new Bitmap(IMG));
Upvotes: 9