Hi, I have some problem in displaying unsigned char* data on QLabel.
Following is my code.
Originally data was "unsigned char*", but it has first converted to "const char*" because I had to write it to QDataStream.
Anyway, i read "const char*" data by "in.readRawData", and converted it to unsigned char*.
sharedMemory.create(1920 * 1080);
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
sharedMemory.unlock();
sharedMemory.detach();
int r_width = 0;
int r_height = 0;
int r_cameraId = 0;
int r_step = 0;
int r_strlen = 0;
in >> r_width >> r_height >> r_step >> r_cameraId >> r_strlen;
char* receive = new char[r_strlen];
in.readRawData(receive, r_strlen);
//unsigned char* r_receive = new unsigned char[r_strlen];
//r_receive = (unsigned char*)receive;
QPixmap backBuffer
= QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step,
QImage::Format::Format_RGB888));
ui.label->setPixmap(backBuffer.scaled(ui.label->size(), Qt::KeepAspectRatio));
ui.label->show();
QBuffer buffer;
QDataStream in(&buffer);
sharedMemory.create(1920 * 1080);
buffer.setData((char*)sharedMemory.constData(), sharedMemory.size());
buffer.open(QBuffer::ReadOnly);
sharedMemory.unlock();
sharedMemory.detach();
int r_width = 0;
int r_height = 0;
int r_cameraId = 0;
int r_step = 0;
int r_strlen = 0;
in >> r_width >> r_height >> r_step >> r_cameraId >> r_strlen;
char* receive = new char[r_strlen];
in.readRawData(receive, r_strlen);
//unsigned char* r_receive = new unsigned char[r_strlen];
//r_receive = (unsigned char*)receive;
QPixmap backBuffer = QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step, QImage::Format::Format_RGB888));
ui.label->setPixmap(backBuffer.scaled(ui.label->size(), Qt::KeepAspectRatio));
ui.label->show();
To copy to clipboard, switch view to plain text mode
But When I ran my code and debugged it, there was some problem in converting data to image.
I think converting unsigned char* to QPixmap like following code is right, but it doesn't work well and also with Format_RGB888, Index8, etc.
(unsigned char* data was made by ffmpeg video.)
QPixmap backBuffer
= QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step,
QImage::Format::Format_RGB888));
QPixmap backBuffer = QPixmap::fromImage(QImage((unsigned char*)receive, r_width, r_height, r_step, QImage::Format::Format_RGB888));
To copy to clipboard, switch view to plain text mode
please share your idea!
thank you!
Bookmarks