5.7作业

 将一张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;
}

运行结果为:

 思维导图为:

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值