View Full Version : Retrieve QByteArray in .png from SQL database
sam123
8th July 2016, 14:51
hello
I have stored image in arraybyte in database and I am also able to run a query to retrieve arraybyte in QPixmap and displaying on QLable.
I want to retrieve the same arraybyte from database but this time I have to store that file in automatic generated folder (Any name) with the format of PNG.
What classes I can use to generate folder for storing my image file ?
How to save the QPixmap in any folder or directory ?
QPixmap::save() just gives boolean value...but does it save file in a specific location?
Looking for your guidance..
Thanks in advance...
Lesiok
8th July 2016, 15:03
Simply use correct variant of method QPixmap::save (http://doc.qt.io/qt-4.8/qpixmap.html#save).
anda_skoa
8th July 2016, 17:20
Which format do you get the date in when you query the database?
If it is PNG already you could just write the data directly into a file.
If you need to decode it first, e.g. if it is saved in a different format in the database, then use QImage for loading/saving if you don't need to display it.
(saves two conversions between QImage and QPixmap)
Cheers,
_
sam123
12th July 2016, 09:47
my image data is in bytes only. I am trying to save byte data using QPixmap::save in specific directory but I am not getting any png file in that specific folder.
Added after 8 minutes:
code for saving byte image in specific folder.
QPixmap pix ("C:/Folder");
QByteArray bytes = dataFromDatabase; //It is a byteArray data
QBuffer buf(&bytes);
buf.open(QIODevice::WriteOnly);
pix.save(&buf, "PNG");
I used this code to save png file in folder but after running this code I am not getting any file in that folder.
anda_skoa
12th July 2016, 10:14
my image data is in bytes only
You mean like 32-bit ARGB or similar?
I used this code to save png file in folder but after running this code I am not getting any file in that folder.
If you want to save to a png file, why do you write into the buffer?
Cheers,
_
sam123
12th July 2016, 10:25
yes its similar, what would be the correct method to save png in specific folder. Could you please suggest me.
anda_skoa
12th July 2016, 11:37
Either use QFile instead of the buffer or just use the save() overload that takes a filename.
Cheers,
_
P.S.: as I said before, if you don't need to display the image use QImage instead of forcing two QImage<->QPixmap conversions
Lesiok
12th July 2016, 12:45
From line 1 of code : You try to work with QPixmap from file Folder in main directory of disk C:. Is this what You want ? I don't think so.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.