This is the original try:


This animated GIF adds square photos to a 3x4 grid one at a time.  There are thirteen frames in the anaimation.

The ninth frame shows the wrong colors in the previous photo that was added.  That is corrrected in the next frame.  Watch the photo added to the third row down in the second column.

This behavior always happens with these photos, but may or not happen with other photos or a different background color.

The source code for this is shown below.

This is the code for the original try:

Public Sub build_animated_gif_ORIG()
   Dim hAniGIF As Long
   Dim hFrame As Long
   Dim i As Long
   Dim Tag As FREE_IMAGE_TAG
   Dim tag_return As Boolean

   ' Create a new multipage image
   hAniGIF = FreeImage_OpenMultiBitmap(FIF_GIF, DataPath + "/tmp/animated.gif", 1, 0)

   For i = 0 To 12
      hFrame = FreeImage_Load(FIF_JPEG, DataPath + "/tmp/animate" + Format(i, "00") + ".jpg")
      
      ' Convert to a color 8bpp image
      hFrame = FreeImage_ConvertColorDepth(hFrame, FICF_PALLETISED_8BPP, True)
      
      ' Append the animation metadata
      Call FreeImage_AppendTag(hFrame, FIMD_ANIMATION, "FrameTime", FIDT_LONG, 600, 9000)
      Call FreeImage_AppendTag(hFrame, FIMD_ANIMATION, "DisposalMethod", FIDT_BYTE, 1)
      If (i = 0) Then
         Tag = FreeImage_CreateTagEx(FIMD_ANIMATION, "Loop", FIDT_LONG, 0, 1)
         tag_return = FreeImage_SetMetadataEx(hFrame, Tag, "Loop", FIMD_ANIMATION, True)
      End If
   
      ' Append the frame to the multipage GIF.
      Call FreeImage_AppendPage(hAniGIF, hFrame)
   
      ' Prevent memory leaks, unload the current frame.
      Call FreeImage_Unload(hFrame)
   Next i
   
   ' Save the multipage image
   Call FreeImage_CloseMultiBitmap(hAniGIF)
End Sub

This is a try using a web-safe palette:

This animated GIF is the same as above except I'm trying to use a palette from a GIF image that has only the 216 web safe colors.

In this try, the colors are improperly displayed and changed a lot more than in the first sample.

This is the code using a web-safe palette:

Public Sub build_animated_gif_web_safe()
   Dim hAniGIF As Long
   Dim hFrame As Long
   Dim colors_gif As Long
   Dim safe_colors As Long
   Dim tmp_frame As Long
   Dim i As Long
   Dim Tag As FREE_IMAGE_TAG
   Dim tag_return As Boolean
   
   ' Create a new multipage image
   hAniGIF = FreeImage_OpenMultiBitmap(FIF_GIF, DataPath + "/tmp/animated.gif", 1, 0)
   
   ' Get a web-safe color palette
   colors_gif = FreeImage_Load(FIF_GIF, App.Path + "/images/web_safe_colors2.gif")
   safe_colors = FreeImage_GetPalette(colors_gif)

   For i = 0 To 12
      tmp_frame = FreeImage_Load(FIF_JPEG, DataPath + "/tmp/animate" + Format(i, "00") + ".jpg")
      
      ' Convert to a color 8bpp image
      hFrame = FreeImage_ColorQuantizeEx(tmp_frame, FIQ_WUQUANT, False, 216, 216, safe_colors)
      
      ' Append the animation metadata
      Call FreeImage_AppendTag(hFrame, FIMD_ANIMATION, "FrameTime", FIDT_LONG, 600, 9000)
      Call FreeImage_AppendTag(hFrame, FIMD_ANIMATION, "DisposalMethod", FIDT_BYTE, 1)
      If (i = 0) Then
         Tag = FreeImage_CreateTagEx(FIMD_ANIMATION, "Loop", FIDT_LONG, 0, 1)
         tag_return = FreeImage_SetMetadataEx(hFrame, Tag, "Loop", FIMD_ANIMATION, True)
      End If
      
      ''' Call FreeImage_AppendTag(hFrame, FIMD_ANIMATION, "GlobalPalette", FIDT_PALETTE, safe_colors, 216)
      ''' Call FreeImage_AppendTag(hFrame, FIMD_ANIMATION, "NoLocalPalette", FIDT_BYTE, 1)

      ' Append the frame to the multipage GIF
      Call FreeImage_AppendPage(hAniGIF, hFrame)
   
      ' Prevent memory leaks, unload the current frame
      Call FreeImage_Unload(hFrame)
      Call FreeImage_Unload(tmp_frame)
   Next i
   
   ' Save the multipage image
   Call FreeImage_CloseMultiBitmap(hAniGIF)
End Sub

Here are the pictures used for the 13 frames:

First frame - blank
Second frame
Third frame
fourth frame
Fifth frame
Sixtht frame
Seventh frame
Eighth frame
Ninth frame
Tenth frame
Eleventh frame
Twelth frame
Last frame