-2

So i have a camera over ethernet. In SDK there are event OnNewFrame(int lPicFormat, int lWidth, int lHeight, int lDataSize, QVariant &pvData), where pvData is interesting array of image bytes. So, i need to convert this array to QT understanding format and show in form(for example in label). Can anybody help me?

user3418460
  • 13
  • 1
  • 7
  • Take a look at QPixmap::loadFromData like this http://stackoverflow.com/questions/6826683/load-qpixmap-from-qbytearray-in-qt – Leo Chapiro Jun 13 '16 at 09:19
  • @duDE function QPixmap::loadFromData returns false. I think, it's because my pvData array hasn't any headers. It's usual array of bits/pixel. – user3418460 Jun 13 '16 at 10:08

2 Answers2

1

Display your array into a label

QByteArray mByteArray;
QPixmap mPixmap;
mPixmap.loadFromData(mByteArray,"JPG");
ui->label->setPixmap(mPixmap);

and check what mpixmap.loadFromData(data,"JPG"); returns. If it returns false then it could not load your data. If you want to display QByteArray as image, look at this: How to display a QByteArray as an Image

Mara Black
  • 1,666
  • 18
  • 23
0

QImage provide several constructor Look at http://doc.qt.io/qt-4.8/qimage.html#QImage-6. Then you can use the QPixmap::fromImage method http://doc.qt.io/qt-4.8/qpixmap.html#fromImage to convert the image to a QPixmap and set to a QLabel

Daniele
  • 26
  • 3