4

I'm using Qt 5.2 and I have a QImage. If it detects an image url (such as an imgur link) it downloads that image and displays it. I want to also animate it if the image is animated (such as a gif).

I tried going by extension, but some links will end in jpg and still be animated. I'm currently using QImage::format() to check for Format_ARGB32_Premultiplied but I've come across some animated images that come back as Format_RGB32 or Format_ARGB32 which is the same format as static images.

Is there a better way that I can check that header info to get more consistent results?

László Papp
  • 51,870
  • 39
  • 111
  • 135
Ben
  • 764
  • 4
  • 19

1 Answers1

7

Use QImageReader to read the image, and QImageReader::supportsAnimation() and QImageReader::imageCount() to check if it's an animated image. Once you have only a QImage, that information will be lost, as QImage represents only one frame, i.e. a static image.

To display animated images, use QMovie. In QtQuick, the element AnimatedImage displays animated images.

Frank Osterfeld
  • 24,815
  • 5
  • 58
  • 70
  • I was reluctant to try this at first because it looked like it required a file on the disk, and I wanted to do it from memory. Upon further investigation it looks like QBuffer inherits QIODevice which would work perfectly. – Ben Dec 19 '13 at 22:27