求看,求围观,求解答
//将二十四位位图作灰度化处理#include<stdio.h>
#include<string.h>
void main()
{
FILE *fp1,*fp2;
unsigned char n;
unsigned buff[55];
int width,i;
int height;
char flag[] = {'\0','\0','\0'};
fp1 = fopen("e:\\a.bmp","rb");
fp2 = fopen("e:\\b.bmp","wb");
fread(flag,1,2,fp1);
if(strcmp(flag,"BM")!=0)
{
printf("文件不存在\n");
fclose(fp1);
fclose(fp2);
}
fseek(fp1,18,SEEK_SET);
fread(&width,1,4,fp1);
fread(&height,1,4,fp1);
rewind(fp1);
rewind(fp2);
fread(buff,1,54,fp1);
fwrite(buff,1,54,fp2);
for(i=0;i<height*width;i++)
{
fread(buff,1,3,fp1);
n = (buff[0]+buff[1]+buff[2])/3;
fwrite(&n,1,1,fp2);
fwrite(&n,1,1,fp2);
fwrite(&n,1,1,fp2);
}
}