简体   繁体   English

GIF动画TImage / Timage32

[英]GIF animation TImage/Timage32

The goal is to have animated GIFs playing inside image components with good image quality even after resizing one of the image components. 目标是让动画GIF在图像组件内部播放时具有良好的图像质量,即使在调整了其中一个图像组件的大小之后也是如此。

TImage example TImage示例

This is the resized TImage , very bad image quality but flawless animation: 这是调整大小的TImage ,图像质量很差但动画效果完美:

图像示例

// GIF = TGIFImage
// TImage = TImage
GIF.Animate := True;
TImage.Stretch := True;
TImage.Proportional := True;
TImage.Picture.Assign(GIF);

TImage32 example TImage32示例

This is a resized TImage32 from the graphics32 library, very good image quality but no animation at all, only the first frame ist visible: 这是来自graphics32库的经过调整大小的TImage32 ,图像质量非常好,但根本没有动画,只有第一帧可见:

graphics32示例

// GIF = TGIFImage
// TImage32 = TImage32
GIF.Animate := True;
TImage32.ScaleMode := smResize;
TImage32.BitmapAlign := baCenter;
TImage32.Bitmap.Assign(GIF);

I need to have the TImage32 component play the animation or for the TImage component to have better resampling. 我需要让TImage32组件播放动画,或者让TImage组件具有更好的重采样。

Graphics32 is not meant to display animations (like in a GIF) out of the box. Graphics32并非旨在开箱即用地显示动画(如GIF中的动画)。 Furthermore it does not contain a native GIF decoder. 此外,它不包含本地GIF解码器。 The code you show relies on the internal TPicture decoder from Delphi. 您显示的代码依赖于Delphi的内部TPicture解码器。 A conversion to TImage32 with assign will only copy the first frame and thus it will result in a still image. 转换为带有Assign的TImage32只会复制第一帧,因此将产生静止图像。

In order to display animations you need further code. 为了显示动画,您需要更多代码。 As mentioned in the comments it would make sense to first copy the each frame of the GIF to a TBitmap32 instance (TImage32 has too much overhead). 如评论中所述,首先将GIF的每个帧复制到TBitmap32实例(TImage32有太多开销)是有意义的。 Than you need to perform the animation. 比您需要执行动画。 If possible this should relate to the display refresh rate or take at least the time interval since the last drawing into account. 如果可能,这应该与显示刷新率有关,或者至少考虑自上次绘制以来的时间间隔。

If for example your monitor uses 60fps and your gif contains 30 frames per second than you need to display each frame for two refresh cycles. 例如,如果您的显示器使用60fps,并且gif每秒包含30帧,则您需要在两个刷新周期中显示每一帧。 Though, this would be an easy situation. 虽然,这将是一个简单的情况。

Things will get slightly more complicated if your gif contains 29 frames per second (for example). 如果您的gif每秒包含29帧(例如),事情将会变得稍微复杂一些。 You need to develop an algorithm to pick the right frame for the current time. 您需要开发一种算法来选择当前时间的正确帧。

So far I have not seen any implementation of the above for Graphics32, but it's not that complicated once you know what to do. 到目前为止,我还没有看到针对Graphics32的上述任何实现,但是一旦知道要怎么做,它并没有那么复杂。

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

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