首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >QMovie webp帧口吃

QMovie webp帧口吃
EN

Stack Overflow用户
提问于 2018-11-26 03:30:15
回答 1查看 521关注 0票数 1

我使用QMovie在QLabal上播放webp动画,代码如下:

代码语言:javascript
复制
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帧,代码如下:

代码语言:javascript
复制
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:

代码语言:javascript
复制
// 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最新版本(我正在尝试)都存在这个问题。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-11-27 10:14:07

这似乎是一个Qt错误,这个bug已经在Qt版本5.9.1:WebP:动画不尊重alpha上报告了

Qt说这个错误在5.9.2版本上已经解决了,但是问题仍然存在,甚至QT5.11也是如此。

有官方的解决方案

代码语言:javascript
复制
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.添加一些代码

代码语言:javascript
复制
// ${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);
}
  1. 重建qt webp插件

nmake module-qtimageformats

  1. 替换qwebp.dll

mv ${QT_DIR}/plugins/imageformats/qwebpd.dll ${QT_DIR}/plugins/imageformats/qwebpd.dll.bak

cp ${REBUILD_WEBP_PLUGINS} ${QT_DIR}/plugins/imageformats/qwebpd.dll

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53474445

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档