练习:
将一张图片修改为德国国旗
1 #include <stdio.h>2 #include <string.h>3 #include <stdlib.h>4 #include <sys/types.h>5 #include <unistd.h>6 #include <sys/stat.h>7 #include <fcntl.h>8 #include <pthread.h>9 #include <semaphore.h>10 #include <wait.h>11 #include <signal.h>12 #include <sys/socket.h>13 #include <arpa/inet.h>14 #include <sys/socket.h>15 #include <sys/ipc.h>16 #include <sys/sem.h>17 #include <semaphore.h>18 #include <sys/msg.h>19 #include <sys/shm.h>20 #include <sys/un.h>21 int main(int argc, const char *argv[])22 {23 FILE *rfp=fopen("./QQ图片20240507160640.bmp","r");24 if(!rfp)25 {26 perror("rfp:");27 return -1;28 }29 int bmp_size=0;30 int width=0;31 int hight=0;32 fseek(rfp,2,SEEK_SET);33 fread(&bmp_size,4,1,rfp);34 printf("文件大小为:%d",bmp_size);35 fseek(rfp,18,SEEK_SET);36 fread(&width,4,1,rfp);37 fread(&hight,4,1,rfp);38 printf("文件信息为:%d * %d\n",width,hight);39 fclose(rfp);40 FILE *wfp=fopen("./QQ图片20240507160640.bmp","r+");41 if(!wfp)42 {43 perror("wfp:");44 return -1;45 }46 char c[3]={0,255,255};47 fseek(wfp,54,SEEK_SET);48 for(int i=0;i<width;i++)49 {50 for(int j=0;j<hight/3;j++)51 {52 fwrite(c,3,1,wfp);53 }54 }55 c[1]=0;56 for(int i=0;i<width;i++)57 {58 for(int j=0;j<hight/3;j++)59 {60 fwrite(c,3,1,wfp);61 }62 }63 c[2]=0;64 for(int i=0;i<width;i++)65 {66 for(int j=0;j<hight/3;j++)67 {68 fwrite(c,3,1,wfp);69 } 70 }71 fclose(wfp);72 return 0;73 }