It doesn't look to be too much information in the internet regarding this.

This is a image extractor for animated gifs.

There are different file formats that have multiple images in them, like some ico files and some tif files. In a gif file, the animation occurs when the sequence of images inside it are displayed. These images are extracted by the programs and then sent to the display, one at a time with some set delay. There are several decoders in the framework to interpret the bytes in the files as an image.

The different pictures in a gif animation, called frames are bitmaps that can be extracted and saved individually.

I made my program to be able to save the frames in some of the more popular formats, but there are others supported in the framework.

If you didn't create the animation and you do need to edit it or to save a still image for further manipulaton, yo do need to separate it from the other pictures. And then, probably you would like to assemble it again.

But the images inside a gif animaton have no individual names, but they have a required order to display properly, so you need to save them to disk with related names and a sequence to be able to keep that order at reassembling.

One of the best ways is to use an index that increases in every loop of the extraction. But there is a glitch: when sorting the images, that could be several dozens, the numbers are treated as characters and sorted alphabetically from the left-most characters to the right. So, a generated sequence of, lets say, 250 frames, you have several problems in the ordering:

If you assemble them, you will have a strage behaviour, and a little jerky animation. So you need to rename them manually or name them at the creation time with a name that will keep it's place in the ordering. I did accomplish this by inserting zeros to the left of the index on the proper situations. I use a prefix, some zeros and a suffix:
Frames & 000,00,0 & i & .jpg

Public Function GetNewName(ByVal Prefix As String, ByVal Suffix As String) As String
Dim i As Integer
Dim str As String = ""
For i = 0 To 10000
If i < 10 Then str = Prefix & "000" & i.ToString & Suffix
If i > 9 And i < 100 Then str = Prefix & "00" & i.ToString & Suffix
If i > 99 And i < 1000 Then str = Prefix & "0" & i.ToString & Suffix
If i > 999 Then str = Prefix & i.ToString & Suffix
If Not System.IO.File.Exists(str) Then
Exit For
End If
Next
Return str
End Function

I am guessing that 3 zeros as maximum will allow you up to 10,000 frames... That's a lot of images, and probably, there are not too many gifs with few hundreds.

The suffix includes the file extension to use and it will be according to the encoder you are using.

The file type is selected from a combobox that is loaded at form load, and the prefix is typed in a textbox:

My default are Frames and jpg, because I plan to use them further, but you could select the more suitable encoder for your use. I have been playing with some code to write the animation and I have a working code, but my animations are a little bulky. You could find some free encoders on the internet.

This code is not used in the current project, but in another program I made to resize and crop animations. I think it would be interesting for some of you. It is a modification of a code from Rick van den Bosch that I found at this address: