20240806

思维导图

#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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值