CreateDIBSection創建位圖

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;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章