Converting QPixmap to QByteArray

From Qt Wiki
Revision as of 09:34, 24 February 2015 by Maintenance script (talk | contribs)
Jump to navigation Jump to search

English Български

Convert QPixmap to QByteArray

This is one way to convert "QPixmap":http://doc.qt.nokia.com/latest/qpixmap.html to "QByteArray":http://doc.qt.nokia.com/latest/qbytearray.html.

Useful when you want to store a pixmap in a database etc.

<br />QPixmap pixmap;<br />// Preparation of our QPixmap<br />QByteArray bArray;<br />QBuffer buffer( &amp;bArray );<br />buffer.open( QIODevice::WriteOnly );<br />pixmap.save( &amp;buffer, &quot;PNG&amp;quot; );<br />

Now variable bArray contains the byte array form of pixmap.

Categories
snippets