Converting QPixmap to QByteArray: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 3: Line 3:
= Convert QPixmap to QByteArray =
= 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.
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.
Useful when you want to store a pixmap in a database etc.


<code><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 /></code>
<code>
QPixmap pixmap;
// Preparation of our QPixmap
QByteArray bArray;
QBuffer buffer( &amp;bArray );
buffer.open( QIODevice::WriteOnly );
pixmap.save( &amp;buffer, "PNG" );
</code>


Now variable ''bArray'' contains the byte array form of pixmap.
Now variable ''bArray'' contains the byte array form of pixmap.


'''Categories'''<br />[[snippets]]
'''Categories'''
[[snippets]]

Revision as of 09:55, 25 February 2015

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.

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

Now variable bArray contains the byte array form of pixmap.

Categories snippets