hi all!
I'm trying to:
1. read a bmp grey scale 8 bit file image, and extract data matrix
2. create a new bmp file with the same header and data matrix of the first
but I haven't a copy of the first file image.
I know that I can do the file copy with a while EOF charbychar, but I must do this type of copy, because I must modify image data matrix and after write it in the new bmp file.
To extract data matrix from the original file, after defining bitmap header:
1 2 3 4 5 6 7 8 9 10
|
fseek(fd, hdr.offset - sizeof(hdr) - sizeof(infoHdr), SEEK_CUR);
for(y = 0; y < infoHdr.height; y++){
for(x = 0; x < infoHdr.width; x++){
(*data_matrix)[(y * infoHdr.width + x)] = fgetc(fd);
}
//padding
for(x = 0; x < (4 - (3 * infoHdr.width) % 4) % 4; x++)
fgetc(fd);
}
| |
To create a copy of the original file image:
1 2 3 4 5 6
|
a=fread(&hdr, sizeof(BMPHeader), 1, origine);
fwrite(&hdr, sizeof(BMPHeader), 1, copy);
a=fread(&infoHdr, sizeof(BMPInfoHeader), 1, origine);
fwrite(&infoHdr, sizeof(BMPInfoHeader), 1, copy);
fseek(copy, sizeof(BMPHeader) + sizeof(BMPInfoHeader), SEEK_SET);
fwrite(new_data_matrix,256*256*sizeof(unsigned char),1,copy);
| |
but I don't get the same image, also if data_matrix==new_data_matrix
thank you very much for help!
Bye
ps:sorry for my bad english! ;)