Don*_*oni 10 c++ qt image bytearray file
我在Qt 4中遇到了写入非文本文件的问题.我有一个QByteArray数据,我想将它保存到特定目录中名为"some_name.ext"的文件:"C:// MyDir".我怎样才能做到这一点?请注意,内容不是文本.
格式为"GIF",Qt不支持.
QImage mainImage;
if (!mainImage.loadFromData(aPhoto.data))
return false;
if (!mainImage.save(imageName, imageFormat.toUtf8().constData()))
return false;
Run Code Online (Sandbox Code Playgroud)
我想以某种方式绕过那个限制!
Nik*_* C. 32
要将QByteArray写入文件:
QByteArray data;
// If you know the size of the data in advance, you can pre-allocate
// the needed memory with reserve() in order to avoid re-allocations
// and copying of the data as you fill it.
data.reserve(data_size_in_bytes);
// ... fill the array with data ...
// Save the data to a file.
QFile file("C:/MyDir/some_name.ext");
file.open(QIODevice::WriteOnly);
file.write(data);
file.close();
Run Code Online (Sandbox Code Playgroud)
当然,请记住检查错误.
另请注意,即使这回答了您的问题,但它可能无法解决您的问题.