QImage img(path); QByteArray ba; QBuffer buf(&ba); buf.open(QIODevice::WriteOnly); //需要加这句才能成功!!! img.save(&buf, "jpeg"); QByteArray ba2 = ba.toBase64(); QString b64str = QString::fromLatin1(ba2);
QImage img(path); QByteArray ba; QBuffer buf(&ba); buf.open(QIODevice::WriteOnly); //需要加这句才能成功!!! img.save(&buf, "jpeg"); QByteArray ba2 = ba.toBase64(); QString b64str = QString::fromLatin1(ba2);