0

This basic example is working on macOS with the same TGA file but for some reason on windows with this particular file the output is as in the provided image.

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

output.tga:

enter image description here

Other tga files that I've tried work fine. What difference with ifstream on windows could be causing the issue? You can find the tga here https://people.math.sc.edu/Burkardt/data/tga/tga.html

  • 1
    Your output stream doesn't appear to be binary. – Mark Setchell May 01 '21 at 15:28
  • FYI -- What you should have done to debug the situation is to load the good output file and the bad output file in a hex editor, and observe the differences. If you did that, you may have noticed extraneous characters. You don't debug image issues by just looking at the pictures. – PaulMcKenzie May 01 '21 at 15:41

0 Answers0