尽管占位符在那里,但您提到的大多数事件都没有(正如您发现的那样)实现。大约十年前,当对该装置进行重大修改时,它们似乎已经消失了GifImg
。
但是,通过另一种方法,您可以解决您提到的问题。那就是TGIFRenderer
单独声明,这使您可以访问所需的信息。
示例应用程序如下所示:
type
TForm22 = class(TForm)
Button1: TButton;
OpenDlg: TOpenDialog;
SaveDlg: TSaveDialog;
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
private
r: TRect;
gif: TGifImage;
rend: TGIFRenderer;
procedure GifChange(Sender: TObject);
public
end;
implementation
procedure TForm22.Button1Click(Sender: TObject);
begin
if not OpenDlg.Execute() then Exit;
// the following is 12 by default to be as slow as Mozilla in last millenium
GIFDelayExp := 10; // set to 10 for correct timing
gif:= TGIFImage.Create;
gif.LoadFromFile(OpenDlg.FileName);
gif.OnChange := GifChange;
r := Rect(0, 0, Gif.Width, Gif.Height);
r.offset((Image1.Width-Gif.Width) div 2, (Image1.Height-Gif.Height) div 2);
rend := TGIFRenderer.Create(Gif);
rend.Animate := True;
rend.StartAnimation;
rend.Draw(Image1.Canvas, r);
//Set animate to true at the end, otherwise an exception at address will be raised.
gif.Animate := True;
end;
procedure TForm22.GifChange(Sender: TObject);
begin
rend.Draw(Image1.Canvas, r);
Label1.Caption := Format('Frame nr %d / %d',[rend.FrameIndex, gif.Images.Count]);
Label2.Caption := Format('Per frame: %d ms',[rend.FrameDelay]);
Label3.Caption := Format('Full cycle: %d s',[rend.FrameDelay * gif.Images.Count]);
end;
使用TGifRenderer.FrameIndex
,您可以计算问题TGifImage.Images.Count
的TGifRenderer.FrameDelay
答案。