最近在程序中遇到要把图片的二进制string存成图片到本地,其实就是写文件
structCameraInfo tmpCameraInfo; string strData = tmpCalibrateReq.images(i).data(); string strCameraName = tmpCalibrateReq.images(i).camera_name(); QFile file; QString strImgPath = qApp->applicationDirPath() + "/" + QString::fromStdString(strCameraName) + ".jpg"; file.setFileName(strImgPath); if(file.open(QIODevice::WriteOnly)) { //QByteArray tmpByteArray = QString::fromStdString(strData).toLatin1();这种写法是错误的
QByteArray tmpByteArray(strData.c_str(), strData.length());//这才是正确的 file.write(tmpByteArray); file.close(); }
https://cloud.tencent.com/developer/ask/32018
这个链接解释的很清楚