PDA

View Full Version : Problem with loading an Image from raw data



Dark Harlekin
10th January 2017, 09:55
Hi everybody,

I'm trying to load an image from raw data, which I get from a database.
For testing purpose I saved the data to a file and wrote the code below but it won't display the image.
I'm not that into processing images, maybe I'm missing something else.

the raw image (https://1drv.ms/u/s!AhdzagALuaiZkizEwRBwrHcOpXjO)
an exported version of the image (https://1drv.ms/i/s!AhdzagALuaiZki3EGiwbTUCAMU87)


QByteArray imagesData;
QFile *file = new QFile(QFileDialog::getOpenFileName(this,tr("Open Image"), "", tr("")));

if(file->exists())
{
//get byteArray from raw data file
file->open(QFile::ReadOnly);
imagesData = file->readAll();
file->close();

//Create qimage
QImage img((const uchar*)imagesData.data(),4320,2880,QImage::Format_ RGB888);

QPixmap pix;
pix.fromImage(img);

ui->label->setPixmap(pix);
}

thanks :)

anda_skoa
10th January 2017, 13:36
Well, you are setting an null pixmap on the label, so it will by definition be empty.

You probably didn't see the "static" keyword in the signature of QPixmap::fromImage()

Cheers,
_

Dark Harlekin
10th January 2017, 14:26
I did miss that one out but it is still not working, seems like this isn't correct.

QImage img((const uchar*)imagesData.data(),4320,2880,QImage::Format_ RGB888);

d_stranz
10th January 2017, 15:55
So why aren't you simply calling QPixmap::load() or QPixmap::loadFromData() instead of going through this circuitous route of reading the data, creating a QImage and then converting that to a pixmap?

Dark Harlekin
10th January 2017, 16:13
What I get from the database is a raw dump without a header, so I can't use QPixmap::load() or QPixmap::loadFromData().
The file is avaible in the first post, maybe I'm missing something again.

d_stranz
11th January 2017, 04:05
Are you certain that the raw dump from the database doesn't contain header information? It would seem odd to store an image as a blob but only after stripping off the header. And are you sure the image dimensions are correct? A 4320 x 2880 pixel image with one byte per color channel should be around 37 MB. The rawImage file you posted is only 4 MB.

Dark Harlekin
11th January 2017, 07:06
You are right, the filesize doesn't really fit and I tried to load the raw file but it didn't work.
I really have no idear, it seems like its the jpg file without a header but as I said I'm really not into grafiks.

Lesiok
11th January 2017, 08:13
Or ask the author of these images.