Converting QPixmap to QByteArray: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
No edit summary
 
No edit summary
Line 1: Line 1:
'''English''' [[Converting QPixmap to QByteArray Bulgarian|Български]]
'''English''' [[Converting_QPixmap_to_QByteArray_Bulgarian|Български]]


=Convert QPixmap to QByteArray=
= Convert QPixmap to QByteArray =


This is one way to convert [http://doc.qt.nokia.com/latest/qpixmap.html QPixmap] ''[doc.qt.nokia.com]'' to [http://doc.qt.nokia.com/latest/qbytearray.html QByteArray] ''[doc.qt.nokia.com]''.
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>


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


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

Revision as of 09:34, 24 February 2015

English Български

Convert QPixmap to QByteArray

This is one way to convert "QPixmap&quot;:http://doc.qt.nokia.com/latest/qpixmap.html to "QByteArray&quot;: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