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