【问题标题】:There is no Format_RGB24 in qt6qt6中没有Format_RGB24
【发布时间】:2021-12-05 15:41:25
【问题描述】:

在 QT5 中,我们有 QVideoFrame::Format_RGB24 格式(我有没有 alpha 通道的 RGB 图像)。

在 QT6 (6.2.0) 中缺少这种格式。

为什么这种格式已被删除? 在 QT6 中转换 RGB -> RGBX (A) 的最佳方法是什么?

【问题讨论】:

  • @eyllanesc 它像 0xRRGGBB 数据数组一样存储。但我认为我可以将其转换为 QImage。

标签: qt qt6


【解决方案1】:

如果您使用的是 QImage(或者您可以将其转换为 QImage),那么您可以将格式转换为 QImage::Format_RGBX8888,然后复制位:

#include <QGuiApplication>
#include <QImage>
#include <QVideoFrame>
#include <QVideoFrameFormat>

int main(int argc, char *argv[])
{
    QGuiApplication a(argc, argv);
    QImage image(100, 100, QImage::Format_RGB888);
    image.fill(QColor(50, 100, 200));

    if(image.format() == QImage::Format_Invalid)
        return EXIT_FAILURE;
    QVideoFrameFormat video_frame_format(image.size(), QVideoFrameFormat::Format_RGBX8888);
    QImage rgbx = image.convertToFormat(QVideoFrameFormat::imageFormatFromPixelFormat(video_frame_format.pixelFormat()));
    QVideoFrame video_frame(video_frame_format);
    if(!video_frame.isValid() || !video_frame.map(QVideoFrame::WriteOnly)){
        qWarning() << "QVideoFrame is not valid or not writable";
        return EXIT_FAILURE;
    }
    int plane = 0;
    std::memcpy(video_frame.bits(plane), rgbx.bits(), video_frame.mappedBytes(plane));
    video_frame.unmap();

    qDebug() << video_frame << rgbx.format();

    return EXIT_SUCCESS;
}

【讨论】:

  • 非常感谢! std::memcpy(..., image.bits(), ...); 应替换为 std::memcpy(..., rgbx.bits(), ...);
  • @KapustinAlexander 哎呀,谢谢
猜你喜欢
  • 2021-08-11
  • 1970-01-01
  • 2022-01-20
  • 2021-11-20
  • 2021-10-05
  • 2021-12-12
  • 2022-01-21
  • 2021-07-29
  • 2023-02-22
相关资源
最近更新 更多