PDA

View Full Version : Convert QPixmap to QByteArray ?



probine
2nd May 2006, 14: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, 14: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, 15: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, 15:57
I guess you must do something like that


QByteArray screenshot;
screenshot.setRawData(e.text().data(),e.text().len ght());

JandunCN
13th March 2014, 08:10
How to convert QPixmap to QByteArray ? I encountered the problem now.

stampede
13th March 2014, 08:23
You have the answer in second post.