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