Created
November 12, 2022 07:34
-
-
Save DJm00n/34fba6e2b2f57e706e780214eb490281 to your computer and use it in GitHub Desktop.
CTransBmp::CreateMask(CDC* pDC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void CTransBmp::CreateMask(CDC* pDC) | |
{ | |
m_hbmMask = new CBitmap; | |
// Nuke any existing mask | |
if (m_hbmMask) m_hbmMask->DeleteObject(); | |
// Create memory DCs to work with | |
CDC* hdcMask = new CDC; | |
CDC* hdcImage = new CDC; | |
hdcMask->CreateCompatibleDC(pDC); | |
hdcImage->CreateCompatibleDC(pDC); | |
// Create a monochrome bitmap for the mask | |
m_hbmMask->CreateBitmap(GetWidth(), | |
GetHeight(), | |
1, | |
1, | |
NULL); | |
CBitmap* pTempBmp; | |
// Select the mono bitmap into its DC | |
CBitmap* hbmOldMask = hdcMask->SelectObject(m_hbmMask); | |
// Select the image bitmap into its DC | |
CBitmap* hbmOldImage = hdcImage->SelectObject(pTempBmp->FromHandle((HBITMAP)m_hObject)); | |
// Set the transparency color to be the top-left pixel | |
hdcImage->SetBkColor(hdcImage->GetPixel(0, 0)); | |
// Make the mask | |
hdcMask->BitBlt(0, 0, | |
GetWidth(), GetHeight(), | |
hdcImage, | |
0, 0, | |
SRCCOPY); | |
// clean up | |
hdcMask->SelectObject(hbmOldMask); | |
hdcImage->SelectObject(hbmOldImage); | |
delete hdcMask; | |
delete hdcImage; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment