我正在编写一个程序来反转位图图像的颜色。我在unsigned char RGB值上使用〜运算符来反转颜色,print语句显示数字被正确反转。但是我觉得我的fwrite可能出了问题,因为图像没有变化。
void invert_colors(struct head h, FILE* filep, struct dib_h dibh){
fseek(file_p, (int)*h.offset_to_pixels, SEEK_SET);
int wid;
int len;
struct pixel pix;
for (len = 0; len < (int)*dibh.imgheight; len++){
for (wid = 0; wid < (int)*dibh.imgwidth; wid++){
fread(&pix, 3, 1, filep);
pix.red = ~(pix.red);
pix.green = ~(pix.green);
pix.blue = ~(pix.blue);
fseek(filep, -3, SEEK_CUR);
fwrite(pix, 3, 1, filep);
}
fseek(filep, (((int)*dibh.imgwidth)*3)%4, SEEK_CUR);
}
fclose(filep);