AnimatedImage QML Type
播放存储为一系列图像的动画。更多
Import Statement: | import QtQuick |
Inherits: |
属性
- currentFrame : int
- frameCount : int
- paused : bool
- playing : bool
- source : url
- sourceSize : size
- speed : real
(since QtQuick 2.11)
详细说明
AnimatedImage 类型扩展了Image 类型的功能,提供了一种播放存储为包含一系列帧的图像(如 GIF 文件中存储的图像)的动画的方法。
通过currentFrame 和frameCount 属性,可以获得有关当前帧和动画总长度的信息。通过更改playing 和paused 属性的值,可以启动、暂停和停止动画。
支持格式的完整列表可通过QMovie::supportedFormats() 查看。
使用示例
下面的 QML 演示了如何显示动画图像并获取其状态信息,如当前帧和总帧数。结果是一幅动画图像,图像下方有一个简单的进度指示器。
注:当动画图像被缓存时,动画的每一帧都将被缓存。
如果要播放较长或较大的动画,并希望节省内存,请将缓存设为 false。
如果图像数据来自顺序设备(如套接字),则只有将缓存设为 true 时,AnimatedImage 才能循环播放。
import QtQuick Rectangle { width: animation.width; height: animation.height + 8 AnimatedImage { id: animation; source: "animation.gif" } Rectangle { property int frames: animation.frameCount width: 4; height: 8 x: (animation.width - width) * animation.currentFrame / frames y: animation.height color: "red" } }
另请参阅 BorderImage 和Image 。
属性文档
currentFrame 是当前可见的框架。通过监控此属性的变化,您可以在图像动画的同时为其他项目制作动画。
frameCount 是动画的帧数。对于某些动画格式, 不详,其值为零。frameCount
paused : bool |
此属性表示动画图像是否暂停。
默认情况下,此属性为 false。如果要暂停动画,请将其设置为 true。
playing : bool |
该属性显示动画图像是否正在播放。
默认情况下,此属性为 true,表示动画将立即开始播放。
注意:该属性会受到AnimatedImage 实际播放状态变化的影响。如果使用的是非动画图片,则需要将playing 手动设置为true ,以便为后续图片制作动画。
AnimatedImage { onStatusChanged: playing = (status == AnimatedImage.Ready) }
source : url |
该属性包含指向源图像的 URL。
AnimatedImage Qt Image Formats 可以处理 Qt 支持的任何图像格式,并从 Qt 支持的任何 URL 方案中加载。但它与 不兼容。QQuickImageProvider
sourceSize : size |
该属性包含全帧图像的宽度和高度缩放比例。
与缩放图像画幅的width 和height 属性不同,该属性为缓存帧设置了最大存储像素数,这样大型动画就不会占用超过必要的内存。
如果原始尺寸大于sourceSize
,图像将被缩放。
可通过将此属性设置为undefined
来恢复图像的自然尺寸。
注意: 动态更改此属性会导致重新加载图像源,如果图像源不在磁盘缓存中,甚至可能从网络上加载。
另请参阅 Image::sourceSize 。
speed : real |
该属性表示动画的速度。
速度以原始动画图像速度的百分比为单位。默认速度为 1.0(原始速度)。
该属性在 QtQuick 2.11 中引入。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.