Creating and Saving an Animated GIF File example for C++ Builder

The following example creates a multi-page file and saves it as an animated GIF image:

void __fastcall TForm2::AnimateGIFClick(TObject *Sender)
{
   int nAngle;

   Lead1->Load("c:\\lead\\images\\image1.cmp", 0, 0, 1);
   Lead1->Size(Lead1->BitmapWidth / 5, Lead1->BitmapHeight / 5, SIZE_RESAMPLE);
   Lead2->Bitmap = 0;
   for (nAngle=1000; nAngle<=36000; nAngle+=1000)
   {
      /* add a new page to the list */
      Lead2->InsertBitmapListItem(LST_APPEND, Lead1->Bitmap);
      /* make the new page active */
      Lead2->BitmapListIndex = Lead2->BitmapListCount-1;
      /* rotate each page 10 degrees more than the previous */
      Lead2->Rotate(nAngle, False, clBlack);
      Lead2->BitmapDelay = 100;
   }
   Lead2->AnimationLoop = True;
   Lead2->Save("c:\\temp\\Animated.gif", FILE_GIF, 8, 0, SAVE_OVERWRITE);
   /* clear all the images in the list */
   Lead2->BitmapList = 0;
   /* start playing upon loading */
   Lead1->AutoAnimate = True;
   /* load the image that was saved */
   Lead1->Load("c:\\temp\\Animated.gif", 0, 0, -1);
}