将一张bmp图片,修改成德国国旗
#include <pthread.h>
#include <semaphore.h>
#include <wait.h>
#include <signal.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <semaphore.h>
#include <sys/msg.h>
#include <sys/shm.h>
#include <sys/un.h>
int main(int argc, const char *argv[])
{
FILE *fp=fopen("./测试(第 3 个复件).bmp","r+");
if(fp==NULL)
{
perror("fopen");
return 1;
}
int bmp_size;
int weight;
int height;
fseek(fp,2,SEEK_SET);
fread(&bmp_size,4,1,fp);
printf("%d\n",bmp_size);
fseek(fp,18,SEEK_SET);
fread(&weight,4,1,fp);
fread(&height,4,1,fp);
printf("%d*%d\n",weight,height);
fseek(fp,54,SEEK_SET);
char bgr[3]={0,0,0}; //黑色
char rgb[3]={39,205,255}; //黄色
char grb[3]={16,38,218}; //红色
for(int i=0;i<295;i++)
{
for(int j=0;j<weight;j++)
{
fwrite(rgb,3,1,fp);
}
}
for(int i=0;i<295;i++)
{
for(int j=0;j<weight;j++)
{
fwrite(grb,3,1,fp);
}
}
for(int i=0;i<295;i++)
{
for(int j=0;j<weight;j++)
{
fwrite(bgr,3,1,fp);
}
}
printf("图片处理完毕\n");
fclose(fp);
return 0;
}
运行结果为:
思维导图为: