Problem with loading an Image from raw data
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
an exported version of the image
Code:
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);
pix.fromImage(img);
ui->label->setPixmap(pix);
}
thanks :)
Re: Problem with loading an Image from raw data
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,
_
Re: Problem with loading an Image from raw data
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);
Re: Problem with loading an Image from raw data
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?
Re: Problem with loading an Image from raw data
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.
Re: Problem with loading an Image from raw data
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.
Re: Problem with loading an Image from raw data
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.
Re: Problem with loading an Image from raw data
Or ask the author of these images.