Bitmap文件格式通常包含 54(不固定)个字节的文件头 + 数据部分
数据部分存储方式采用 从左到右,从下到上,如下图所示:
即图像的存储方式与显示方式是镜面对称的(上下翻转)
下面的程序只能读取 24(RGB)位真彩色图像
#include
#pragma comment(lib, "ImageShow.lib")
extern "C" __declspec(dllimport) void ShowImage(unsigned char *data, int rows, int cols);
int rows;
int cols;
unsigned char *buffer = NULL;
void ReadHeader(FILE *fp)
{
unsigned char bytes[4]; //一次读 4 个字节
fseek(fp, 18, SEEK_SET); // 跳过前18个字节,读取Width, Height
//read Width
fread(bytes, 1, 4, fp);
cols = bytes[0] + (bytes[1] << 8) + (bytes[2] << 16) + (bytes[3] << 24);
//read Height
fread(b