【问题标题】:set QPixmap to texture将 QPixmap 设置为纹理
【发布时间】:2013-10-28 10:23:36
【问题描述】:

我收到一个字节数组,其中包含来自网络的 PNG 文件。我需要将其设置为像素图并将其设置为我的 QGlWidget 的纹理。当我运行下面的程序时,pixmap 处于调试模式并且不包含任何内容。但是,bytes 包含从网络接收到的整个字节数组。

void MainWindow::dataFromServer(QByteArray bytes)
{
//    QByteArray bytes;
    QBuffer    buffer(&bytes);

    QPixmap pixmap;
//    pixmap = QPixmap::grabWidget(this);

    buffer.open(QIODevice::WriteOnly);

    pixmap.save(&buffer, "PNG"); // writes pixmap into bytes in PNG format

    emit sendPixmapToWidget(pixmap);
}

在这里我将像素图设置为纹理:

void GlWidget::pixmapCatchFromForm(QPixmap pixmap)
{
    deleteTexture(texture);

//    image->loadFromData(bytes, "PNG");

    texture = bindTexture(pixmap);

    qDebug() << texture; // returns 1

    updateGL();
}

【问题讨论】:

    标签: qt opengl qt4 qt5


    【解决方案1】:

    QPixmap::save(..)QPixmap 的内容保存到缓冲区,您确定要使用QPixmap::loadFromData(..) 来做相反的事情吗?

    【讨论】:

      猜你喜欢
      • 2016-04-09
      • 1970-01-01
      • 2020-11-22
      • 2021-08-14
      • 1970-01-01
      • 1970-01-01
      • 2019-06-03
      • 1970-01-01
      • 2020-11-06
      相关资源
      最近更新 更多