简体   繁体   English

使用多线程将动画 GIF 图像放在 VCL 上

[英]Use of multithreading to put an animated GIF image on the VCL

I want to show a (animated) GIF in a TImage (GIF) while the main programming is running.我想在主程序运行时在 TImage (GIF) 中显示(动画)GIF。 Right now, either the main program waits for the GIF, or the GIF is waiting for the main program (thread) before showing.现在,要么主程序等待 GIF,要么 GIF 等待主程序(线程)才显示。

My idea is that the GIF Image should be run in a separate thread.我的想法是 GIF 图像应该在单独的线程中运行。 The GIF image is not used elsewhere in the main program. GIF 图像未在主程序的其他地方使用。 I have read a lot about multi-threading (new to me).我已经阅读了很多关于多线程的内容(对我来说是新的)。 Delphi allows me to build a new thread in a separate unit (a built-in feature), but many on-line examples and tutorials just put the TThread object on the main form. Delphi 允许我在单独的单元中构建一个新线程(一个内置功能),但是许多在线示例和教程只是将 TThread 对象放在主窗体上。 If I do that I get a compiler error that my mainform does not contain a member named 'Execute' See code).如果我这样做,我会收到一个编译器错误,即我的主窗体不包含名为“执行”的成员,请参阅代码)。

What am I doing wrong?我究竟做错了什么? Should I go for the separate thread in the second unit?我应该在第二单元中使用单独的线程吗? Any advise on how to access this GIF (TImage) via this separate thread?关于如何通过这个单独的线程访问这个 GIF (TImage) 的任何建议? I do know that I have to take care of synchronization between the VCL and the separate thread.我知道我必须处理 VCL 和单独线程之间的同步。 I also read that modern Delphi has a Queue possibility, claimed to be superior over synchronization.我还读到现代 Delphi 有一个 Queue 可能性,声称优于同步。

(in the interface section): (在界面部分):

type
  TThreadGIF = class(TThread)
  protected
    procedure Execute; override;
  end;

(in the implementation section, below the {$R *.dfm}): (在实现部分,在 {$R *.dfm} 下方):

procedure TThreadGIF.Execute;
begin
  NameThreadForDebugging('ThreadGIFname');
  { code should start here }
end;

If anybody knows a reference to a good tutorial, would also help.如果有人知道一个好的教程的参考,也会有所帮助。

How To Build Multithreaded Applications brings me in my current position. 如何构建多线程应用程序使我处于目前的位置。

You don't need a thread at all.你根本不需要线程。 The VCL's existing TGIFImage class, which can be used to display GIF images in a TImage component, already supports animated GIFs. VCL 现有的TGIFImage类可用于在TImage组件中显示 GIF 图像,已经支持动画 GIF。

Look at the following TGIFImage properties:查看以下TGIFImage属性:

Animate

Specifies whether the GIF should be animated.指定是否应为 GIF 设置动画。

The Animate property specifies whether the GIF stored in the TGIFImage instance should be animated when displayed. Animate 属性指定存储在 TGIFImage 实例中的 GIF 在显示时是否应设置动画。

AnimateLoop

Specifies whether the GIF animation should loop.指定 GIF 动画是否应该循环播放。

The AnimateLoop property specifies whether the animation of the GIF stored in the TGIFImage instance should loop. AnimateLoop 属性指定存储在 TGIFImage 实例中的 GIF 动画是否应该循环。

Note: Changing the AnimateLoop property only has effect if the Animate property is set to True.注意:仅当 Animate 属性设置为 True 时,更改 AnimateLoop 属性才有效。

AnimationSpeed

Specifies the GIF animation speed.指定 GIF 动画速度。

The AnimationSpeed property specifies the GIF animation speed in percents of the normal speed. AnimationSpeed 属性以正常速度的百分比指定 GIF 动画速度。

The value of AnimationSpeed must be in the range from 0 through 1000. AnimationSpeed 的值必须在 0 到 1000 的范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM