bmp图像格式

BMP file format

typedef struct bmp_header {
	/* Header */
	char signature[2];
	uint32_t	file_size;
	uint32_t	reserved;
	uint32_t	data_offset;
	/* InfoHeader */
	uint32_t	size;
	uint32_t	width;
	uint32_t	height;
	uint16_t	planes;
	uint16_t	bit_count;
	uint32_t	compression;
	uint32_t	image_size;
	uint32_t	x_pixels_per_m;
	uint32_t	y_pixels_per_m;
	uint32_t	colors_used;
	uint32_t	colors_important;
	/* ColorTable */

} __attribute__ ((packed)) bmp_header_t;
  • signature[2] - 标志位 'BM'表示Windows下的格式
  • file_size - BMP文件大小
  • reserved;
  • data_offset - 文件头到数据区的位移

DIB Header

  • size : DIB头信息的字节数
  • width : width of the bitmap in pixels
  • height - height of the bitmap in pixels
  • planes : 旧设备会用到调色板的概念,现在已经用不到。置1即可
  • bit_count : number of bits per pixel,每个像素占用的位数
  • compression : 压缩方式。最常用的是BI_RGB,表示不压缩
  • image_size : 数据区的大小,单位为字节
  • x_pixels_per_m : 水平方向上每米的像素个数
  • y_pixels_per_m : 垂直方向上每米的像素个数
  • colors_used : 调色板上颜色个数
  • colors_important : 重要颜色的个数,0表示每个颜色都重要。此值常忽略

另外需要注意数据区中,每行都要4字节对齐

原文地址:https://www.cnblogs.com/sammei/p/3976870.html