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

被折叠的 条评论
为什么被折叠?



