Converting QPixmap to QByteArray: Difference between revisions

From Qt Wiki
Jump to navigation Jump to search
(Add "cleanup" tag)
(Cleanup)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
{{Cleanup | reason=Auto-imported from ExpressionEngine.}}
{{LangSwitch}}
 
[[Category:snippets]]
'''English''' [[Converting_QPixmap_to_QByteArray_Bulgarian|Български]]
This is one way to convert {{DocLink|QPixmap}} to {{DocLink|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.


Useful when you want to store a pixmap in a database etc.
Useful when you want to store a pixmap in a database etc.
Line 13: Line 9:
// Preparation of our QPixmap
// Preparation of our QPixmap
QByteArray bArray;
QByteArray bArray;
QBuffer buffer( &bArray );
QBuffer buffer(&bArray);
buffer.open( QIODevice::WriteOnly );
buffer.open(QIODevice::WriteOnly);
pixmap.save( &buffer, "PNG" );
pixmap.save(&buffer, "PNG");
</code>
</code>


Now variable ''bArray'' contains the byte array form of pixmap.
Now variable ''bArray'' contains the byte array form of pixmap.
'''Categories'''
[[snippets]]

Latest revision as of 12:51, 28 June 2015

En Ar Bg De El Es Fa Fi Fr Hi Hu It Ja Kn Ko Ms Nl Pl Pt Ru Sq Th Tr Uk Zh

This is one way to convert QPixmap to QByteArray.

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

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

Now variable bArray contains the byte array form of pixmap.