简体   繁体   English

如何使用 delphi 形式的 Animated Gif

[英]How to use Animated Gif in a delphi form

I think theres no native support to gif animated images.我认为没有对 gif 动画图像的本机支持。

How is the best way?最好的方法是怎样的? any free component that allow that?任何允许这样做的免费组件? I was thinking in using a TImage and a ImageList + Timer, but I need to export each frame of the gif to a separated bmp file.我正在考虑使用 TImage 和 ImageList + Timer,但我需要将 gif 的每一帧导出到一个单独的 bmp 文件。

It's pretty simple in modern Delphi.这在现代 Delphi 中非常简单。 It's all built in. Drop a TImage onto the form and load the animated GIF into the Picture property.这一切都是内置的。将TImage拖放到窗体上并将动画 GIF 加载到 Picture 属性中。 Then, start the animation by means of the Animate property:然后,通过Animate属性启动动画:

(Image1.Picture.Graphic as TGIFImage).Animate := True;

You can control the animation with AnimateLoop and AnimateSpeed .您可以使用AnimateLoopAnimateSpeed控制动画。 It should be pretty easy to guess how to switch the animation off again!猜测如何再次关闭动画应该很容易!

Now, since you are using Delphi 7, you don't have the TGIFImage component built-in.现在,由于您使用的是 Delphi 7,因此您没有内置TGIFImage组件。 However, you can download the code from Finn Tolderlund's website (you want the latest version of TGIFImage ).但是,您可以从Finn Tolderlund 的网站下载代码(您需要最新版本的TGIFImage )。 With this version of the component, the code above should work fine, although I personally have not used it since I ported from D6 to D2010 a few years back.使用这个版本的组件,上面的代码应该可以正常工作,尽管我个人自从几年前从 D6 移植到 D2010 后就没有使用过它。

All these various TGIFImage codes are really just versions of the same component, originally written by Anders Melander and, in 2007, donated to Embarcadero for inclusion in Delphi.所有这些不同的TGIFImage代码实际上只是同一组件的版本,最初由Anders Melander编写,并于 2007 年捐赠给 Embarcadero 以包含在 Delphi 中。

this is simply loading an animated gif and not making one这只是加载一个动画 gif 而不是制作一个

procedure TForm1.FormCreate(Sender: TObject);

begin

  ( Image1.Picture.Graphic as TGIFImage ).Animate := True;// gets it goin'

  ( Image1.Picture.Graphic as TGIFImage ).AnimationSpeed:= 500;// adjust your speed

  Form1.DoubleBuffered := True;// stops flickering

end;

stackoverflow has helped me and so my little bit in return :) stackoverflow 帮助了我,所以我的一点点回报:)

Searched Google for 'Delphi Gif' Came up with this在 Google 上搜索“Delphi Gif” 想出了这个

http://melander.dk/delphi/gifimage/ http://melander.dk/delphi/gifimage/

now part of Delphi现在是德尔福的一部分

If you happen to use JVCL, like me, you will likely run into trouble with Davids answer , because JVCL registers TJvGifImage for GIF files which does not descent from TGifImage (see comments to Davids answer ).如果你碰巧使用JVCL,像我一样,你可能会遇到麻烦戴维斯回答,因为JVCL注册TJvGifImage对于不从血统GIF文件TGifImage (见注释戴维斯回答)。

In this case the easiest solution seems to be loading the GIF file directly from resources:在这种情况下,最简单的解决方案似乎是直接从资源加载 GIF 文件:

//eg in FormCreate:
FAnimationGraphic := TGifImage.Create;
FAnimationGraphic.LoadFromResourceName(HInstance, 'GIF_XYZ_ANIMATION');
ImageAnimation.Picture.Graphic := FAnimationGraphic;

(ImageAnimation.Picture.Graphic as TGIFImage).Animate := True;

//eg in FormDestroy:
//FAnimationGraphic must be freed! 
//ImageAnimation.Picture is not owner of the image
FreeAndNil(FAnimationGraphic);

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

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