#include <my_head.h>
typedef struct Color{
unsigned char b;
unsigned char g;
unsigned char r;
unsigned char a;//透明度 0 全透明 255 不透明
}color_t;
int main(int argc, const char *argv[]){
if(2 != argc){
printf("Usage : %s filename\n", argv[0]);
return -1;
}
FILE *fp = NULL;
if(NULL == (fp = fopen(argv[1], "r+")))
ERR_LOG("fopen error");
char bfType[2] = {0};
fread(bfType, 1, 2, fp);
printf("bfType = %s\n", bfType);//BM
int bfSize = 0;
fread(&bfSize, 1, 4, fp);
printf("bfSize = %d\n", bfSize);//大小
int offset = 0;
fseek(fp, 4, SEEK_CUR);
fread(&offset, 1, 4, fp);
printf("offset = %d\n", offset);//偏移量
int biWidth = 0;
fseek(fp, 4, SEEK_CUR);
fread(&biWidth, 1, 4, fp);
printf("biWidth = %d\n", biWidth);//宽度
int biHeight = 0;
fread(&biHeight, 1, 4, fp);
printf("biHeight = %d\n", biHeight);//高度
short bitCount = 0;
fseek(fp, 2, SEEK_CUR);
fread(&bitCount, 1, 2, fp);
printf("bitCount = %d\n", bitCount);//位深度
//想操作图片内容 需要把光标定位到第一个像素点的位置
fseek(fp, offset, SEEK_SET);
//将光标定位到鼻子左上角的像素点
fseek(fp, bitCount/8 * (325*biWidth+595), SEEK_CUR);
color_t c = {0, 255, 0, 255};
int i = 0;
int j = 0;
//外层循环控制行数
for(i = 0; i < 419-325; i++){
//填充一行颜色
for(j = 0; j < 691-595; j++){
fwrite(&c, 1, 4, fp);
}
//定位光标到下一行
fseek(fp, bitCount/8 * (biWidth-(691-595)), SEEK_CUR);
}
fclose(fp);
return 0;
}
给图像进行指定区域颜色变换
最新推荐文章于 2024-05-04 14:49:56 发布