QByteArray
转化为 QImage
:
QImage image;
QByteArray ba;
image.loadFromData(ba);
QImage
转化为 QByteArray
:
1
QImage image;
QByteArray imageArray;
QBuffer buffer;
buffer.open(QIODevice::WriteOnly);
image.save(&buffer,"PNG");
imageArray.append(buffer.data());
2
QImage image;
QByteArray ba;
QBuffer buffer(&ba);
buffer.open(QIODevice::WriteOnly);
image.save(&buffer, "PNG"); // write image into ba in PNG format
转自 How to Store and Retrieve Image on SQLite:
QPixmap inPixmap;//store it in a QByteArray
QByteArray inByteArray;
QBuffer inBuffer( &inByteArray );
inBuffer.open( QIODevice::WriteOnly );
inPixmap.save( &inBuffer, "PNG" ); // write inPixmap into inByteArray in PNG format