Creating and Saving an Animated GIF File example for Delphi
The following example creates a multi-page file and saves it as an animated GIF image:
procedure TForm2.AnimateGIFClick(Sender: TObject);
var
nAngle: Integer;
begin
Lead1.Load('c:\lead\images\image1.cmp', 0, 0, 1);
Lead1.Size(Lead1.BitmapWidth div 5, Lead1.BitmapHeight div 5, SIZE_RESAMPLE);
Lead2.Bitmap := 0;
for nAngle := 1 to 36 do
begin
{ 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 * 1000, False, clBlack);
Lead2.BitmapDelay := 100;
end;
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);
end;