Home > Blockchain >  Does QMovie support an alpha channel?
Does QMovie support an alpha channel?

Time:09-28

I swapped out QImageReader for QMovie to easily loop an animated GIF. However, the QImage returned by QMovie::currentImage() does not have an alpha channel. If I use QImageReader::read(), it does have an alpha channel. The documentation does not mention any difference between the two regarding alpha. Is there any way to preserve the alpha channel when using QMovie?

QMovie movie( "ExampleAnimation.gif" );
movie.jumpToFrame( 0 );
const auto movieFrame = movie.currentImage();
DEBUG_LOG() << movieFrame.hasAlphaChannel(); // false

QImageReader reader( "ExampleAnimation.gif" );
reader.jumpToImage( 0 );
const auto readerImage = reader.read();
DEBUG_LOG() << readerImage.hasAlphaChannel(); // true

CodePudding user response:

I figured out the issue and I would like to provide an answer in case others are in a similar situation.

The GIF file I was using had an alpha channel, but it didn't have any transparent pixels. Internally, QMovie calls QPixmap::fromImage(), which seems to remove the alpha channel if it is not used.

  •  Tags:  
  • c qt
  • Related