【问题标题】:QWidget::grab function for videos: cannot catch视频的 QWidget::grab 功能:无法捕捉
【发布时间】:2015-12-03 08:58:04
【问题描述】:

我想将当前窗口保存到 Qt 中的图像(如 ATL+PrintScreen)。例如Qt Media Player Example(搜索“播放器”时可以得到Qt Creator示例中的所有代码,我将此代码添加到player.h

//private slots:
...
void exportVideoToImages();

player.cpp:

void Player::exportVideoToImages()
{
    qDebug() << "ok";
    QPixmap const& px = grab();
    px.save("File.png");
}

将此行添加到构造函数以触发插槽:

new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_G), this, SLOT(exportVideoToImages()));

所以,当我触发 CTRL+G 时,我会收到一个图像“File.png”。它工作,但问题是无法捕捉播放的视频。

这是两张图片,一张来自 Alt+PrintScreen,一张来自程序:

为什么会这样?如何在 Qt 中抓取视频?能给我看看吗?
非常感谢!

【问题讨论】:

    标签: c++ qt video-capture


    【解决方案1】:

    我找到了解决办法:

    QScreen *screen = QGuiApplication::primaryScreen();
    if (screen) {
        QPixmap px =screen->grabWindow(this->winId());
        px.save("screen.png");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-03
      • 1970-01-01
      相关资源
      最近更新 更多