微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 Windows 上读取和写入 TGA 文件会产生不正确的输出

如何解决在 Windows 上读取和写入 TGA 文件会产生不正确的输出

此基本示例在具有相同 TGA 文件的 macOS 上运行,但出于某种原因,在具有此特定文件的 Windows 上,输出与提供的图像相同。

std::ifstream input_file("C:\\Users\\Michael\\Desktop\\earth.tga",std::ios::binary);

input_file.seekg(0,std::ios::end);
std::size_t length = input_file.tellg();
input_file.seekg(0,std::ios::beg);
std::vector<char> data(length);
input_file.read(data.data(),length);

std::ofstream output_file("C:\\Users\\Michael\\Desktop\\output.tga",std::ofstream::out);

output_file.write(data.data(),data.size());

earth.tga:

earth.tga

输出.tga:

enter image description here

我尝试过的其他 tga 文件工作正常。与 Windows 上的 ifstream 有什么区别可能会导致问题?您可以在此处找到 tga https://people.math.sc.edu/Burkardt/data/tga/tga.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。