I have image file with header and metainformation, image data stored after header, I want to rewrite image data, but other data around imagesection is corrupted(header) and file truncated.
How can I done it properly?
Here is the code:
FILE* f = _tfopen(fileName, _T("wb"));
if( f != NULL )
{
uint64 headerSize = 8;
char arr[2*3*3]; //w=3 h=2 RGB
memset(arr,100,2*3*3);
_fseeki64(f, headerSize, SEEK_SET);
fwrite(arr,sizeof(char),sizeof(arr),f);
fclose(f);
}
I think you need to change open mode from your file from
"wb"
to"r+b"
from cplusplus.com:
"w" write: Create an empty file for output operations. If a file with the same name already exists, its contents are discarded and the file is treated as a new empty file.