#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
int main(int argc, const char *argv[])
{
FILE *fp=fopen("5a.bmp","r");
if(fp==NULL){return 1;}
//尺寸
int w=0;
int h=0;
fseek(fp,18,SEEK_SET);
fread(&w,4,1,fp);
fread(&h,4,1,fp);
printf("w:%d\nh:%d\n",w,h);
fclose(fp);
//改色
fp=fopen("5a.bmp","r+");
if(fp==NULL){return 1;}
fseek(fp,54,SEEK_SET);
char s1[3]={0,0,255};
char s2[3]={255,0,0};
char s3[3]={0,255,0};
for(int i=0;i<w;i++)
{
for(int j=0;j<h/3;j++)
{
fwrite(s1,3,1,fp);
}
}
for(int i=0;i<w;i++)
{
for(int j=h/3;j<2*(h/3);j++)
{
fwrite(s2,3,1,fp);
}
}
for(int i=0;i<w;i++)
{
for(int j=2*(h/3);j<h;j++)
{
fwrite(s3,3,1,fp);
}
}
fclose(fp);
return 0;
}