View Full Version : Convert QPixmap to QByteArray ?
probine
2nd May 2006, 15:43
I am using a QPixmap to take a screenshot of my desktop. I would like to convert this QPixMap to QByteArray.
How ?
SkripT
2nd May 2006, 15:49
Have you tried it using QPixmap::save. From the Qt Docs:
QPixmap pixmap;
QByteArray bytes;
QBuffer buffer(&bytes);
buffer.open(QIODevice::WriteOnly);
pixmap.save(&buffer, "PNG");
probine
2nd May 2006, 16:27
Thanks for the answer.
Now I have everything in a QByteArray. Now, I am parsing my QByteArray which has XML format. The parsing is done with DOM.
I need an element of the XML (QByteArray) to be comverted or used as QByteArray.
How ?
I do not want to transform the element to string, because I think I will loose the picture.
void Message :: parseScreenshot(QByteArray incomingMessage)
{
QDomDocument doc("messageIn");
doc.setContent(incomingMessage);
QDomElement docElem = doc.documentElement();
QDomNode n = docElem.firstChild();
n = n.nextSibling();
QDomElement e = n.toElement();
QByteArray screenshot = e // to QByteArray. what should be here ?
chatGui->screenshot(screenshot);
}
zlatko
2nd May 2006, 16:57
I guess you must do something like that
QByteArray screenshot;
screenshot.setRawData(e.text().data(),e.text().len ght());
vBulletin® v3.7.1, Copyright ©2000-2008, Jelsoft Enterprises Ltd.