Converting QPixmap to QByteArray

From Qt Wiki
Revision as of 12:51, 28 June 2015 by Wieland (talk | contribs) (Cleanup)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.