C++: copying bmp using loop of fread and fwrite, casues output bmp is filled with color of the fisrt one in input bmp

StackOverflow https://stackoverflow.com/questions/1884165

  •  19-09-2019
  •  | 
  •  

Question

I dunno why, but first pixel (left bottom) is loaded correctly, but the others won't load and the first color is used for whole picture...

I have this in cycle

fread(&pix,sizeof(pix),1,pictureIn);
fwrite(&pix,sizeof(pix),1,pictureOut);

edit:

pix is struct of three unsigned chars (rgb), loading file and info header seems to be ok

Was it helpful?

Solution

What OS are you using? I recently had problem with reading binary files under Win32. It turned out that I forgot to pass "b" flag to fopen:

pictureIn = fopen ("in.bmp", "rb");
pictureOut = fopen ("out.bmp", "wb");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top