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