我正在创建一个程序,可以读取bmp图像并计算其上的红色,蓝色和绿色的百分比。我已经搜索了很多但是没有理解图像数据从哪个字节开始以及如何获得像素的RGB值?
#include<stdio.h>
typedef struct {
unsigned int fileSize;
unsigned int offset;
unsigned int reserved;
char signature[2];
} BmpHeader;
typedef struct {
unsigned short bitDepth;
unsigned int compressedImageSize;
unsigned int compression;
unsigned int headerSize;
unsigned int height;
unsigned int horizontalResolution;
unsigned int importantColors;
unsigned int numColors;
unsigned short planeCount;
unsigned int verticalResolution;
unsigned int width;
} BmpImageInfo;
typedef struct {
unsigned char blue;
unsigned char green;
unsigned char red;
} Rgb;
int main(void) {
BmpHeader header;
BmpImageInfo info;
char filename[40];
printf("Enter file name : ");scanf("%s", filename);
FILE *fp;
fp = fopen(filename, "rb");
fread(&header, 1, sizeof(BmpHeader), fp);
fread(&info, 1, sizeof(BmpImageInfo), fp);
printf("%u", info.height);
getchar();
return 0;
}
为什么我得到了错误的高度?
答案 0 :(得分:3)
此链接指向描述.bmp图像格式的Wiki页面。注意事项: