#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#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("./123.bmp","r");
int bmp_size = 0;
int width = 0;
int height = 0;
fseek(fp,2,SEEK_SET);
fread(&bmp_size,4,1,fp);
printf("图片总大小为:%d\n",bmp_size);
fseek(fp,18,SEEK_SET);
fread(&width,4,1,fp);
fread(&height,4,1,fp);
printf("图片的像素信息为:%d * %d\n",width,height);
fclose(fp);
unsigned char black[3] = {0,0,0};
unsigned char yellow[3] = {0,255,255};
unsigned char red[3] = {0,0,255};
fp = fopen("./123.bmp","r+");
fseek(fp,54,SEEK_SET);
for(int i=0;i<(width/3);i++)
{
for(int j=0;j<height;j++)
{
fwrite(yellow,3,1,fp);
}
}
for(int i=(width/3);i<(width/3*2);i++)
{
for(int j=0;j<height;j++)
{
fwrite(red,3,1,fp);
}
}
for(int i=(width/3*2);i<width;i++)
{
for(int j=0;j<height;j++)
{
fwrite(black,3,1,fp);
}
}
fclose(fp);
return 0;
}