Guys,
quick question, is that possible to dump a Qimage in a text file so l can same numerical data and images in a same text file ?
thanks,
Michael
Guys,
quick question, is that possible to dump a Qimage in a text file so l can same numerical data and images in a same text file ?
thanks,
Michael
You can always write an image to a file. It depends on what format you want to write.
text files contains text. Applications will open text files as text files.
If you want to embedd image with text, you can save in doc or pdf format. Qt provides support to write in pdf format. You can opt for that.
Other easy way -
Save QImage as image file...open in paint , copy image and paste in MS Word.
I think the OP wants to save an image and some related, human readable data in the same text file and have the image recoverable even if the user edits the extra data. In this case base64, a start/end marker pair, and a big warning that the user should not edit between the markers might be the best bet.
Just a note that base64 is not efficient for binary data.
I would go for a gzipped folder containing the images as jpg or png and some xml or other config files.
Last edited by tbscope; 2nd August 2010 at 13:51. Reason: typo
you can save your image in QByteArray and then save a QByteArray into file.
take a look at QImage::save.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
thanks guy, got it to work.
Save to text file:
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
QTextStream out(&file);
Image_snapshot.save(&buffer, "PNG");
out << buffer.data().toHex();
load from file:
if(line.contains("#BEGIN_Image"))
{
line = in.readLine();
ba.clear();
while (!line.contains("#END_Image")) {
line = in.readLine();
QTextStream(&ba) << line;
}
QByteArray readCompressed = QByteArray::fromHex(Buffer.toAscii());
if(!WebCam_snapshot.loadFromData(readCompressed))
qDebug() << "fail to load Qbytrearray";
//test image
if(!WebCam_snapshot.save("test.bmp"))
qDebug() << "fail to save image from Qbytrearray";
}
Bookmarks