CreateDIBSection创建位图

这篇博客介绍了如何利用CreateDIBSection函数创建24位和32位位图。在32位位图创建过程中,详细说明了BITMAPINFO结构的设置,包括图像尺寸、位深度、压缩方式等,并给出了设置Alpha通道的步骤。最后,检查创建的位图句柄和数据指针是否有效。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

24位位图:

LPBYTE DIBData;

HBITMAP HBitMapDst;

BITMAPINFO *pbinfo = NULL;
pbinfo = (BITMAPINFO *)calloc(1, sizeof(BITMAPINFO)) ;
if(pbinfo == NULL)
{
return;
}
pbinfo->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
pbinfo->bmiHeader.biWidth = Width;//指定图像尺寸
pbinfo->bmiHeader.biHeight =Length ;
pbinfo->bmiHeader.biPlanes = 1;
pbinfo->bmiHeader.biBitCount = 24;
pbinfo->bmiHeader.biCompression = 0;
pbinfo->bmiHeader.biSizeImage = 0 ;
pbinfo->bmiHeader.biXPelsPerMeter = 2834;
pbinfo->bmiHeader.biYPelsPerMeter = 2834;
pbinfo->bmiHeader.biClrUsed = 0;
pbinfo->bmiHeader.biClrImportant = 0;


HBitMapDst = CreateDIBSection(NULL, pbinfo, DIB_RGB_COLORS, (void **)&DIBData, NULL, 0) ;
free(pbinfo) ;


if((HBitMapDst == NULL) || (DIBData == NULL))
{
return;
}
BITMAP DstBitmap;

GetObject(HBitMapDst,sizeof(BITMAP),&DstBitmap);

32位位图:

LPBYTE DIBData;
BITMAPINFO *pbinfo = NULL;
pbinfo = (BITMAPINFO *)calloc(1, sizeof(BITMAPINFO) + 4 * sizeof(INT)) ;
if(pbinfo == NULL)
{
return;
}
pbinfo->bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
pbinfo->bmiHeader.biWidth = Width;//指定图像尺寸
pbinfo->bmiHeader.biHeight = Height;
pbinfo->bmiHeader.biPlanes = 1;
pbinfo->bmiHeader.biBitCount = 32;
pbinfo->bmiHeader.biCompression = BI_ALPHABITFIELDS;
pbinfo->bmiHeader.biSizeImage = 0 ;
pbinfo->bmiHeader.biXPelsPerMeter = 2834;
pbinfo->bmiHeader.biYPelsPerMeter = 2834;
pbinfo->bmiHeader.biClrUsed = 0;
pbinfo->bmiHeader.biClrImportant = 0;


int *pMask = (int*)&(pbinfo->bmiColors[0]) ;
*pMask++ = 0x00FF0000 ;
*pMask++ = 0x0000FF00 ;
*pMask++ = 0x000000FF ;
*pMask++ = 0xFF000000 ;


hDstBitmap = CreateDIBSection(NULL, pbinfo, DIB_RGB_COLORS, (void **)&DIBData, NULL, 0) ;
free(pbinfo) ;


if((hDstBitmap == NULL) || (DIBData == NULL))
{
return;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值