QImage image;QByteArray ba;QBuffer buffer(&ba);buffer.open(QIODevice::WriteOnly);image.save(&buffer, "PNG"); // writes image into ba in PNG format