Image From Memory to QLabel as Pixmap
-
Hi, i have two variables :
uint8_t jpegData //and uint32_t jpegDataLenWhen i want to write a jpeg file under a directory, i am using these two variables that coming from an external DLL. And i got the JPEG file correctly.
But when i try to show this jpeg data from memory, program getting crashed. Here's what i am doing:
first try:
QImage image; image.loadFromData((char *)array[i].jpegMugData, array[i].jpegMugDataLen, "JPG"); ui->imageLabel->setPixmap(QPixmap::fromImage(image));second try:
QBuffer buffer; QDataStream in(&buffer); QImage image; buffer.setData((char*)array[i].jpegMugData, array[i].jpegMugDataLen); buffer.open(QBuffer::ReadOnly); in >> image; ui->imageLabel->setPixmap(QPixmap::fromImage(image));both ways causes to program crash. Like i said when i used these two variables to write jpeg file under a directory there is no problem. What should i do? What am i missing?
-
Hi, i have two variables :
uint8_t jpegData //and uint32_t jpegDataLenWhen i want to write a jpeg file under a directory, i am using these two variables that coming from an external DLL. And i got the JPEG file correctly.
But when i try to show this jpeg data from memory, program getting crashed. Here's what i am doing:
first try:
QImage image; image.loadFromData((char *)array[i].jpegMugData, array[i].jpegMugDataLen, "JPG"); ui->imageLabel->setPixmap(QPixmap::fromImage(image));second try:
QBuffer buffer; QDataStream in(&buffer); QImage image; buffer.setData((char*)array[i].jpegMugData, array[i].jpegMugDataLen); buffer.open(QBuffer::ReadOnly); in >> image; ui->imageLabel->setPixmap(QPixmap::fromImage(image));both ways causes to program crash. Like i said when i used these two variables to write jpeg file under a directory there is no problem. What should i do? What am i missing?
@R_Irudezu said in Image From Memory to QLabel as Pixmap:
uint8_t jpegData
This is a single byte. If
jpegDataLen>1 it's normal for it to crash.
You need to allocate the buffer beforehand.QByteArrayhelps in these cases -
@R_Irudezu said in Image From Memory to QLabel as Pixmap:
uint8_t jpegData
This is a single byte. If
jpegDataLen>1 it's normal for it to crash.
You need to allocate the buffer beforehand.QByteArrayhelps in these cases