首先去下载gifimage.
下面给出合成四张图片为gif的代码
//uses gifimage
procedure TFormAnimate.ButtonAnimateClick(Sender: TObject);
var
GIF : TGIFImage;
i : integer;
OptimizeOptions : TGIFOptimizeOptions;
gr: TGraphic;
function TransparentIndex(GIF: TGIFSubImage): byte;
begin
// Use the lower left pixel as the transparent color
Result := GIF.Pixels[0, GIF.Height-1];
end;
function AddBitmap(GIF: TGIFImage; Source: TGraphic; Transparent: boolean): integer;
var
Ext : TGIFGraphicControlExtension;
LoopExt : TGIFAppExtNSLoop;
begin
// Preview the image being added (for user feedback)
// ImageAnimate.Picture.Assign(Source);
// ImageAnimate.Update;
// Add the source image to the animation
Result := GIF.Add(Source);
// Netscape Loop extension must be the first extension in the first frame!
if (Result = 0) then
begin
LoopExt := TGIFAppExtNSLoop.Create(GIF.Images[Result]);
LoopExt.Loops := 0; // Number of loops (0 = forever)
GIF.Images[Result].Extensions.Add(LoopExt);
end;
// Add Graphic Control Extension
Ext := TGIFGraphicControlExtension.Create(GIF.Images[Result]);
Ext.Delay := 30; // Animation delay (30 = 300 mS)
if (Transparent) then
begin
Ext.Transparent := True;
Ext.TransparentColorIndex := TransparentIndex(GIF.Images[Result]);
end;
GIF.Images[Result].Extensions.Add(Ext);
end;
begin
Screen.Cursor := crHourGlass;
try
GIF := TGIFImage.Create;
try
// Add all the images in the scroll box to the animation
for i := 0 to ScrollBoxSource.ControlCount-1 do
// Add frame
AddBitmap(GIF, // Destination GIF
TImage(ScrollBoxSource.Controls).Picture.Graphic, // Source bitmap
(i > 0)); // First frame is not transparent
// Optimize Color map...
{ if (CheckBoxPalette.Checked) then
GIF.OptimizeColorMap;
// Optimize GIF frames...
OptimizeOptions := [];
if (CheckBoxMerge.Checked) then
include(OptimizeOptions, ooMerge);
if (CheckBoxCrop.Checked) then
include(OptimizeOptions, ooCrop);
if (OptimizeOptions <> []) then
GIF.Optimize(OptimizeOptions, rmNone, dmNearest, 0);
}
// Display the animation
ImageAnimate.Picture.Assign(GIF);
image7.Picture.Assign(gif);
gr := TGIFImage.Create;//RV_CreateGraphics(TGraphicClass(image7.Picture.Graphic.ClassType));//gif.ClassType));
gr.Assign(gif.Bitmap );
// gr.Assign(image7.Picture.Graphic) ;
RichViewEdit1.InsertPicture('', gr , rvvaBaseLine);
finally
GIF.Free;
end;
ButtonSave.Enabled := True;
finally
Screen.Cursor := crDefault;
end;
end;