把图片改成德国国旗

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, char const *argv[])
{
    FILE *fp = fopen("./ppp.bmp", "r+");
    int width = 0;
    int height = 0;
    int image_size = 0;
 
    int every_bit = 0;
 
    fseek(fp,2,SEEK_SET);
    fread(&image_size, 4, 1, fp);
    printf("image_size == %d\n", image_size);
 
    fseek(fp,0x12,SEEK_SET);
    fread(&width, 4, 1, fp);
    printf("width == %d\n", width);
 
    fseek(fp,0x16,SEEK_SET);
    fread(&height, 4, 1, fp);
    printf("height == %d\n", height);
 
    fseek(fp,0x1c,SEEK_SET);
    fread(&every_bit, 2, 1, fp);
    printf("every_Byte == %d\n", every_bit/8);
 
    fseek(fp,0x36,SEEK_SET);
 
    image_size = image_size - 54; // 计算时去除开头54
    int height_arr[3] = {image_size/9, image_size *2/9, image_size/3};
    unsigned char black_color[3] = {0,0,0};
    unsigned char red_color[3] = {0,0,255};
    unsigned char gold_color[3] = {0,204,255};
 
    fseek(fp,0x36,SEEK_SET);
    for (int i = 0; i < image_size/3 ; i++) {
        if (i < height_arr[0]) {
            fwrite(&gold_color, 3,1,fp);
        } else if (i < height_arr[1]) {
            fwrite(&red_color, 3,1,fp);
        } else {
            fwrite(&black_color, 3,1,fp);
        }
    }
  
    fclose(fp);
    return 0;
}

  • 4
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值