Qt 对图片的base64加密与解密

加密

bool getFileContetBase64(const QString& strFilePath,QString &val)
{
    bool bRet = false;
    if(!strFilePath.isEmpty() && QFileInfo(strFilePath).exists())
    {
        QFile file(strFilePath);
        if(file.open(QIODevice::ReadOnly))
        {
            val = file.readAll().toBase64();
            bRet = true;
        }
        else
        {
            qDebug()<<"打开文件失败"<<endl;
        }
    }
    else
    {
        qDebug()<<"文件路径不存在"<<endl;
    }

    return bRet;
}

 解密

获得解密后的内容显示到QLabel上,假如

void show(QString base64str)
{
    QPixmap pixmap;
    pixmap.loadFromData(QByteArray::fromBase64(base64str.toLocal8Bit()));
    ui.label->setPixmap(pixmap);
}

猜你喜欢

转载自blog.csdn.net/wzz953200463/article/details/104737157