#ifndef __BMP_H__ #define __BMP_H__ #include #pragma pack(push, 1) // 1字节对齐 // BMP文件头结构体 struct BMPFileHeader { uint16_t type; // 文件类型,必须为"BM" uint32_t size; // 文件大小,单位为字节 uint16_t reserved1; // 保留字段,必须为0 uint16_t reserved2; // 保留字段,必须为0 uint32_t offset; // 像素数据起始位置,单位为字节 }; // BMP位图信息头结构体 struct BMPInfoHeader { uint32_t size; // 信息头大小,必须为40 int32_t width; // 图像宽度,单位为像素 int32_t height; // 图像高度,单位为像素 uint16_t planes; // 颜色平面数,必须为1 uint16_t bit_count; // 每个像素的位数,必须为24 uint32_t compression; // 压缩方式,必须为0 uint32_t size_image; // 像素数据大小,单位为字节 int32_t x_pels_per_meter; // X方向像素数/米 int32_t y_pels_per_meter; // Y方向像素数/米 uint32_t clr_used; // 使用的颜色数,必须为0 uint32_t clr_important; // 重要的颜色数,必须为0 }; #pragma pack(pop) bool write_bmp(const char* filename, uint8_t* data, int32_t width, int32_t height); #endif