思维导图
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.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>
typedef struct sockaddr_in addr_in_t;
typedef struct sockaddr addr_t;
typedef struct sockaddr_un addr_un_t;
int main(int argc, const char *argv[])
{
unsigned char a[3] = {0,0,0};//black
unsigned char b[3] = {0,255,255};//yellow
unsigned char c[3] = {0,0,255};//red
FILE *fp = NULL;
if((fp = fopen("./rising_freedom.bmp","r")) == NULL)
{
perror("fopen");
return -1;
}
int size = 0;
unsigned char arr[3] = {0};
unsigned char brr[3] = {0};
int size_w = 0;
int size_h = 0;
fseek(fp,18,SEEK_SET);
fread(&size_w,4,1,fp);
fread(&size_h,4,1,fp);
//1
fseek(fp,2,SEEK_SET);
fread(&size,4,1,fp);
printf("size = %d\n",size);
fseek(fp,54,SEEK_SET);
fread(arr,3,1,fp);
fseek(fp,-4,SEEK_END);
fread(brr,3,1,fp);
printf("%d\n",brr[0]);
fclose(fp);
//2
if((fp = fopen("./rising_freedom1.bmp","r+")) == NULL)
{
perror("fopen");
return -1;
}
fseek(fp,18,SEEK_SET);
int size_w_1 = size_w*2;
int size_h_1 = size_h*2;
fwrite(&size_w_1,4,1,fp);
fwrite(&size_h_1,4,1,fp);
fseek(fp,54,SEEK_SET);
for(int i=0;i<size_w;i++)
{
for(int j=0;j<size_h;j++)
{
if(i>size_w/4)
{
fwrite(a,3,1,fp);
}
}
}
fclose(fp);
//3
if((fp = fopen("./rising_freedom2.bmp","r+")) == NULL)
{
perror("fopen");
return -1;
}
fseek(fp,54,SEEK_SET);
for(int i=0;i<size_w;i++)
{
for(int j=0;j<size_h;j++)
{
if(i<size_w/3)
{
fwrite(b,3,1,fp);
}
else if(i>size_w/3 && i<size_w/3*2)
{
fwrite(c,3,1,fp);
}
else
{
fwrite(a,3,1,fp);
}
}
}
fclose(fp);
return 0;
}