/* 功能: 创建一幅24位真彩色位图
** 作者: mayadong7349
** 参考: MSDN(Visual Studio 2005)、(百度百科:bmp) http://baike.baidu.com/view/7671.htm#2
*/
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#define BMP_W 640L
#define BMP_H 480L
void SetBmpInfoHeader(PBITMAPINFOHEADER pbmpih)
{
/* 14~17: 本结构体所占字节数, 固定值40
MSDN: Specifies the number of bytes required by the structure.
*/
pbmpih->biSize = 40;
/* 18~21: 位图的宽度(以像素pixel为单位)
MSDN: Specifies the width of the bitmap, in pixels.
Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, the biWidth member specifies
the width of the decompressed JPEG or PNG image file, respectively.
*/
pbmpih->biWidth = BMP_W;
/* 22~25: 位图的高度
MSDN: Specifies the height of the bitmap, in pixels. If biHeight is positive, the bitmap is a
bottom-up DIB and its origin is the lower-left corner. If biHeight is negative, the bitmap is
a top-down DIB and its origin is the upper-left corner.
If biHeight is negative, indicating a top-down DIB, biCompression must be either BI_RGB or
BI_BITFIELDS. Top-down DIBs cannot be compressed.
Windows 98/Me, Windows 2000/XP: If biCompression is BI_JPEG or BI_PNG, the biHeight member specifies
the height of the decompressed JPEG or PNG image file, respectively.
*/
pbmpih->biHeight = BMP_H;
/* 26~27: 目标设备的级别, 固定值:1
MSDN: Specifies the number of planes for the target device. This value must be set to 1*/
pbmpih->biPlanes = 1;
/* 28~29: 一个像素所占bit数, 可以是:1(双色)、4(16色)、8(256色)
、16(65536色)、24(真彩色2^24种颜色)、32(真彩色2^32种颜色),具体参阅MSDN。
对于24位真彩色位图, 一个像素占用三个字节,即24 bits
MSDN: Specifies the number of bits-per-pixel. The biBitCount member of the BITMAPINFOHEADER
structure determines the number of bits that define each pixel and the maximum number
of colors in the bitmap. This member must be one of the following values.
0: Windows 98/Me, Windows 2000/XP: The number of bits-per-pixel is specified or is implied
by the JPEG or PNG format.
1: The bitmap is monochrome, and the bmiColors member of BITMAPINFO contains two
C语言创建24位真彩色位图
最新推荐文章于 2024-05-14 18:14:55 发布
本文档提供了使用C语言创建24位真彩色位图的方法,包括设置BITMAPINFOHEADER和BITMAPFILEHEADER结构体,以及位图数据的填充规则。源代码示例展示了如何生成一个640x480像素的位图文件。
摘要由CSDN通过智能技术生成