C语言中使用文件处理函数修改.bmp格式图片的颜色代码

#include<stdio.h>
int main()
{
FILE *fp,*fp1;
fp=fopen("/Users/lanou/Desktop/1.bmp","rb");
fp1=fopen("/Users/lanou/Desktop/6.bmp","wb");
char content,head[54];
unsigned char wrt;
unsigned int no=1;
unsigned char r=0,b=0,g=0;
int no_avg=1;
fread(head,1,54,fp);
fwrite(head,1,54,fp1);
unsigned size = *(unsigned*)(head+2);
size=size-54;
size /= 3;
while(size--)
{
b = getc(fp);
g = getc(fp);
r = getc(fp);
wrt = (b+g+r)/3;
putc(wrt,fp1);
putc(wrt,fp1);
putc(wrt,fp1);
}

printf("OK");

fclose(fp);
fclose(fp1);
}

原文地址:https://www.cnblogs.com/yuanyuandachao/p/3342944.html