0
我正在编写一个程序来反转位图图像的颜色。我在无符号字符RGB值上使用〜运算符来反转颜色,并且打印语句显示数字正确反转。不过我认为也许我的fwrite出了问题,因为图像没有改变。使用C反转位图颜色不会更改图像
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);
完成后文件包含什么内容? – nicomp
这不是[mcve] - 你不显示你如何打开文件。这可能是问题所在。 – usr2564301
@nicomp文件不变 – 3802400