我使用QMovie在QLabal上播放webp动画,代码如下:
Foo::Foo() {
movie_ = new QMovie("/path/to/my.webp", "", this);
ui->label->setMovie(movie_);
}
void Foo::on_pushButton_clicked() {
movie_->stop();
movie_->start();
}但是当我播放动画时,画面会结结巴巴的,就像:

我尝试使用QImage::save提取webp帧,代码如下:
QImageReader *reader = new QImageReader("/path/to/my.webp");
reader->setDecideFormatFromContent(true);
for (int i = 0; i < reader->imageCount(); ++i) {
QImage image;
reader->read(&image);
image.save(QString("frame_%1.png").arg(i));
reader->jumpToNextImage();
}所有提取的帧也都是口吃,例如:

但是当我使用google工具提取框架时,没有任何problem.like:

// extract frame 9, not problem
webpmux.exe -get frame 9 -o "frame_9.webp"
// paly webp animation, there is no any problem
vwebp.exe /path/to/my.webp是Qt问题吗?Qt5.9.4(我正在使用)和Qt最新版本(我正在尝试)都存在这个问题。
发布于 2018-11-27 10:14:07
这似乎是一个Qt错误,这个bug已经在Qt版本5.9.1:WebP:动画不尊重alpha上报告了
Qt说这个错误在5.9.2版本上已经解决了,但是问题仍然存在,甚至QT5.11也是如此。
有官方的解决方案
diff --git a/src/plugins/imageformats/webp/qwebphandler.cpp b/src/plugins/imageformats/webp/qwebphandler.cpp
index 5a0ae4a..ce90158 100644
--- a/src/plugins/imageformats/webp/qwebphandler.cpp
+++ b/src/plugins/imageformats/webp/qwebphandler.cpp
@@ -122,6 +122,8 @@ bool QWebpHandler::ensureScanned() const
that->m_bgColor = QColor::fromRgba(QRgb(WebPDemuxGetI(m_demuxer, WEBP_FF_BACKGROUND_COLOR)));
that->m_composited = new QImage(that->m_features.width, that->m_features.height, QImage::Format_ARGB32);
+ if (that->m_features.has_alpha)
+ that->m_composited->fill(Qt::transparent);
// We do not reset device position since we have read in all data
m_scanState = ScanSuccess;
@@ -193,6 +195,8 @@ bool QWebpHandler::read(QImage *image)
} else {
// Animation
QPainter painter(m_composited);
+ if (m_features.has_alpha && m_iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND)
+ m_composited->fill(Qt::transparent);
painter.drawImage(currentImageRect(), frame);
*image = *m_composited;这是我的解决方案:
1.添加一些代码
// ${QT_SRC}/qtimageformats/src/plugins/imageformats/webp/qwebphandler.cpp
// function QWebpHandler::read
if (m_features.has_alpha && (m_iter.dispose_method == WEBP_MUX_DISPOSE_BACKGROUND ||
m_iter.blend_method == WEBP_MUX_NO_BLEND)) {
m_composited->fill(Qt::transparent);
}nmake module-qtimageformats
mv ${QT_DIR}/plugins/imageformats/qwebpd.dll ${QT_DIR}/plugins/imageformats/qwebpd.dll.bak
cp ${REBUILD_WEBP_PLUGINS} ${QT_DIR}/plugins/imageformats/qwebpd.dll
https://stackoverflow.com/questions/53474445
复制相似问题