找到:https://forum.qt.io/topic/72282/save-qimage-to-base64-string
Qt 图片转为base64编码
我自己稍微改了下

QByteArray toBase64(QString imgPath) {
    QImage image(imgPath);
    QByteArray ba;
    QBuffer buf(&ba);
    image.save(&buf, "png");
    QByteArray hexed = ba.toBase64();
    buf.close();
    return hexed;
}

相关文章: