QImage::loadFromData QByteArray
-
Hi,
One thing is not clear, in your database, do you store only the raw image data (RGB components) ? Or is it a bmp (meaning with header etc... like a file) ?
-
Thank you for your response.
As you can see in the last piece of code, it's just a data stream from a Bitmap.
Actually, that's what I'm trying to do, reproducing that code as QT code. -
Since these are raw bytes, use the constructor of "QImage":http://qt-project.org/doc/qt-4.8/qimage.html#QImage-5 to build it.
Also you don't need to create a new QPixmap, use:
@scene->addPixmap(QPixmap::fromImage(image))@Hope it helps
-
as SGaist already asked: what is the datatype of the stored binary in your database? The code doesn't clears it up.
@DataModuleCET->ADOQuery2->FieldByName("Data")->AsBytes;@Is it really stored in the "BPM file format":http://en.wikipedia.org/wiki/BMP_file_format?
-
Thank you SGaist, but I have posted 2 ways of doing it, one with Pixmap, and anotherone without Pixmap.
I use that only for buffering purposes, but it's not working anyway.raven-worx, as you can see in the last line of the old code:
@IMat->Picture->Bitmap->LoadFromStream(Str);@
it's just a BMP in a Stream format, within a database.
-
Bitmap doesn't necessarily mean that's its really a BMP ... especially when i don't know the framework you are using.
Seems the QByteArray valid?
What happens when you write the QByteArray to a file and check if you can open? -
I also tried to write that data in a file, but no success.
What I realized debugging is that the "Loadfromdata" function is not working with the data I'm inserting.@ IMat->Picture->Bitmap->LoadFromStream(Str);@
The IMat is a TImage from C++ Builder libraries.
The memory Stream contains the Buffer from the query of the Database:@TByteDynArray Buffer=DataModuleCET->ADOQuery2->FieldByName("Data")->AsBytes;@
-
Then are you sure your are not getting only the RGB data of the image ?
-
As it's not working, I'm not sure of anything J
What would be the solution if it were the RGB data? -
If you have somewhere the image size (width, height), you can use QImage giving the proper image format and then make a QPixmap from it
-
Thank you for your help SGaist, I got stuck since I've discovered that the data storaged in that database is coded in a C++ Builder "whoknowshow" system.
I quit and try to find an alternative way.