C语言创建24位真彩色位图

本文档提供了使用C语言创建24位真彩色位图的方法,包括设置BITMAPINFOHEADER和BITMAPFILEHEADER结构体,以及位图数据的填充规则。源代码示例展示了如何生成一个640x480像素的位图文件。
摘要由CSDN通过智能技术生成
/* 功能: 创建一幅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 
  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值