Image From Memory to QLabel as Pixmap
-
Hi, i have two variables :
uint8_t jpegData //and uint32_t jpegDataLen
When 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.QByteArray
helps in these cases -
@VRonin Yes you're right. I did some minor changes on code and it's now being allocating and there is no crash. But still nothing to display over imageLabel. I suppose because of jpg decoding. How to handle it....
Edit: it's ok now.