德尔福的TGIFImage
有以下事件:OnPaint
, OnAfterPaint
, OnLoop
, OnEndPaint
。
但在显示动画 GIF 时,这些事件都不会被调用。
我使用以下代码来显示动画 GIF:
FGif := (Image1.Picture.Graphic as TGIFImage);
FGif.OnProgress := GifProgress;
FGif.OnLoop := GifLoop;
FGif.OnPaint := GifPaint;
FGif.OnEndPaint := GifEndPaint;
FGif.OnAfterPaint := GifAfterPaint;
FGif.Animate := True;
动画播放时如何提取当前可见帧索引?
如何检测动画何时完成?
如何检测下一帧何时显示?
OnProgress
仅在绘制最后一个动画帧后的第一个动画循环期间调用事件 - TGIFImage 将从第一帧继续动画,但此事件停止工作。
我正在使用 Delphi 10.2 东京。
尽管占位符存在,但您提到的大多数事件都没有(正如您所发现的)实现。大约十年前,当对系统进行重大修改时,它们似乎就消失了。GifImg
unit.
然而,通过另一种方法,您可以解决您提到的问题。那就是声明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
and TGifRenderer.FrameDelay
您可以计算问题的答案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)