PDA

View Full Version : set QPixmap to texture



saman_artorious
28th October 2013, 11:30
I receive a byte array which contains PNG file from network. I need to set this to a pixmap and set it as a texture to my QGlWidget. As I run the program below, pixmap is in debug mode and does not contain anything. However, bytes contains the whole byte array received from network.



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);
}


and here I set the pixmap to texture:



void GlWidget::pixmapCatchFromForm(QPixmap pixmap) {

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

texture = bindTexture(pixmap);

qDebug() << texture; // returns 1

updateGL();
}

stampede
28th October 2013, 11:45
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);
}
"I just got a new image data, I will create a buffer from it. Now, I will take empty image and write it over that buffer. Finally, I will send that empty image."
Do you know where is the problem ?:)

saman_artorious
28th October 2013, 11:52
how to do the vice versa? I mean how to write the buffer to empty image? I don't think I need to use a buffer instead simple doing:


QPixmap pixmap(bytes.data());

qDebug() << pixmap.size();

may suffice. but again, the value of pixmap here is inaccessible and size prints (0, 0)!

stampede
28th October 2013, 11:58
QPixmap::loadFromData (http://harmattan-dev.nokia.com/docs/library/html/qt4/qpixmap.html#loadFromData-3)