I need to load GIF animations and convert them frame by frame into bitmaps. To do this, I extract my GIF file frame by frame using the Drawing.Imaging library and then custom-cast each frame into a bitmap image.
Everything works fine, except when consecutive frames are the same, when there is no difference in pixels. It seems that the library leaves such frames.
I came to this conclusion with a simple test. I created an animation of a circle that grows and contracts with a pause between the moment when the last circle disappears and a new one has not yet been shown. When I play an animation consisting of my extracted bitmaps, there is no pause. If I compare GIFs of the same frame length, but with different numbers of identical frames, the totalframescount return value is different. I also noticed that web browsers display the same consecutive frames correctly.
public void DrawGif(Image img) { FrameDimension dimension = new FrameDimension(img.FrameDimensionsList[0]); int frameCountTotal = img.GetFrameCount(dimension); for (int framecount = 0; framecount < frameCountTotal; framecount++) { img.SelectActiveFrame(dimension, framecount); Bitmap bmp = new Bitmap(img);
- Has anyone encountered such a problem?
- As I am pretty new to C # - is there a way to change .NET lib?
- Perhaps there is a solution to my problem, which I do not know about, which is not related to changing the library?
Updated code - same result
public void DrawGif(img) { int frameCountTotal = img.GetFrameCount(FrameDimension.Time); for (int framecount = 0; framecount < frameCountTotal; framecount++) { img.SelectActiveFrame(FrameDimension.Time, framecount); Bitmap bmp = new Bitmap(img); for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { Color color = bmp.GetPixel(i, j); DrawPixel(i, j, 0, color.R, color.G, color.B); }
c # gif animated-gif
PK
source share