我正在编写一个程序,该程序将有一个用户列表,并且每个用户都将拥有来自在线源的自己的图片。 我正在成功下载数据,我正在努力格式化图片格式。 成功保存文件,但不会以可读格式保存。将图片从在线存储到本地存储qt 5.1
void FriendsListProcess::picRequesFinished(QNetworkReply *reply)
{
QByteArray data = reply->readAll();
if(reply->error())
{
qDebug() << reply->errorString();
return;
}
emit savePic(pic_name_path,data);
reply->deleteLater();
}
void FriendsListProcess::savePicToFile(QString file, QByteArray &pic_data)
{
qDebug() << "File name from write pic: " << file;
QFile f(file);
if(f.open(QIODevice::WriteOnly))
{
QDataStream out(&f);
out << pic_data;
f.close();
}
}
当我尝试打开保存文件窗口说
"Windows Photo Viewer can't open this picture because either Photo Viewer doesn't support this file format. or you don't have the lates updates to Photo Viewer"
有你们有什么建议吗?
它是在远程主机上的正确的图像,即它与您的浏览器或wget的,等下载后工作? OT:您的保存方法缺少打开和写入的错误检查。 – lpapp
是的,我可以点击链接打印到我的调试控制台,它下载没有任何问题与任何大师 – TheMan68
为什么你不使用QDataStream这样的二进制数据?图像不是文本流。顺便说一句,如果图像很大,没有通过块读取,你的代码浪费了大量的内存。写入操作是否成功?请检查。 – lpapp