1、利用BitBlt函数将蒙版与背景图做AND运算,并贴图到目的DC
2、将要镂空的图与背景图做OR运算,贴图到目的DC
部分代码:
//取得客户取大小
GetClientRect(&rect);
//建立内存DC
mdc->CreateCompatibleDC(pDC);
//加载背景位图
m_bgBmp.m_hObject=(HBITMAP)::LoadImage(NULL,"b1.bmp",IMAGE_BITMAP,rect.right,rect.bottom,LR_LOADFROMFILE);
//加载人物位图(人物及蒙版同在一张图上)
m_manBmp.m_hObject=(HBITMAP)::LoadImage(NULL,"man.bmp",IMAGE_BITMAP,208,154,LR_LOADFROMFILE);
//取得背景图
mdc->SelectObject(m_bgBmp);
//贴背景图
pDC->BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);
//将蒙版与背景图做AND运算
mdc->SelectObject(m_manBmp);
pDC->BitBlt(250,150,104,154,mdc,104,0,SRCAND);
//将要镂空的图与背景图做OR运算
pDC->BitBlt(250,150,104,154,mdc,0,0,SRCPAINT);
时间: 2024-12-03 03:46:17