1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
HBITMAP HBITMAPfromHDC(HDC hdcimage)
{
//prepare the returnhbitmap for get the size
HBITMAP returnhbitmap;
BITMAP structBitmapHeader;
memset( &structBitmapHeader, 0, sizeof(BITMAP) );
//DeleteBitmap(returnhbitmap);
//get the hdc actual size
returnhbitmap =(HBITMAP) GetCurrentObject(hdcimage, OBJ_BITMAP);
GetObject(returnhbitmap, sizeof(BITMAP), &structBitmapHeader);
//create a hdc for select the returnhbitmap
HDC hMemDC = CreateCompatibleDC(NULL);
//clean the returnhbitmap before create a new one
//DeleteBitmap(returnhbitmap);
returnhbitmap = CreateCompatibleBitmap(hdcimage, structBitmapHeader.bmWidth,structBitmapHeader.bmHeight);
//select returnhbitmap to hMemDC
HBITMAP hBmp2 = (HBITMAP)SelectObject(hMemDC, returnhbitmap);
//copy the hdcimage to hMemDC
BitBlt(hMemDC,0,0,structBitmapHeader.bmWidth,structBitmapHeader.bmHeight,hdcimage,0,0,SRCCOPY);
//unselect the returnhbitmap for return it without problems
SelectObject(hMemDC, hBmp2);
//and then delete the DC
DeleteDC(hMemDC);
return returnhbitmap;
}
//.......
DeleteBitmap(hbmMask);
hbmMask = HBITMAPfromHDC(HBitmap);
|