Search code examples
qtanimationqmlqt5image-formats

How to Animate an Image with more than 256 colors (i.e. not a GIF) using AnimatedImage or otherwise


I can use AnimatedImage in Qt 5.9 which works on GIFs like this;

import QtQuick 2.7
import QtQuick.Controls 2.2

ApplicationWindow
{
    visible: true
    width: 640
    height: 480

    Rectangle 
    {
        width: animation.width; 
        height: animation.height + 8

        AnimatedImage 
        {
            id: animation;
            source: "myanimation.gif"
        }

        Rectangle {

            height: 8
            width: animation.currentFrame/animation.frameCount * animation.width
            y: animation.height
            color: "red"

            Component.onCompleted: console.log("framecount ", animation.frameCount);
        }
    }
}

I get a lot of error messages too. This is printed over and over;

QQmlExpression: Expression qrc:/main.qml:26:20 depends on non-NOTIFYable properties:
    QQuickAnimatedImage::frameCount

I took my example code from here; http://doc.qt.io/qt-5/qml-qtquick-animatedimage.html

which doen't work at all, something wrong with putting frameCount into a property, so i changed that in my version.

I would like to animate a png like an apng. Apparently there used to be mng support, but it is not there anymore.

So i call QMovie::supportedFormats which returns only GIF (on Windows).

My question:

How can i either use AnimatedImage on a format that supports non-palettised color (eg png etc) or is there another way to animate an image that would work?

Thanks for any info.


Solution

  • It seems like those image formats are not shipped with the standard installation of Qt/QML. You can however install them as a plugin.

    See: