TransparentBlt is limited in that it does not support any size other than the original size of the image. Stretching and shrinking are not supported.
The only way to do transparency in GDI with scaling support is to create a mask image from the original image. The mask image is then blitted used SRC_AND and the original image is blitted using SRC_PAINT.
To create a mask:
Code:
void CTileGDI::PrepareMask(void)
{
//AfxMessageBox(L"Preparing mask");
CMainFrame *pFrame=(CMainFrame *)AfxGetMainWnd();
//AfxMessageBox(L"Creating DCs");
CDC *pMaskDC=new CDC();
pMaskDC->CreateCompatibleDC(NULL);
CDC *pDC=new CDC();
pDC->CreateCompatibleDC(NULL);
//AfxMessageBox(L"Creating mask");
m_pMask=new CBitmap;
m_pMask->CreateBitmap(m_iTileW,m_iTileH,1,1,NULL);
//AfxMessageBox(L"Selecting objects into DCs");
CBitmap *pPrevSource=(CBitmap *)pDC->SelectObject(m_pImage);
CBitmap *pPrevMask=(CBitmap *)pMaskDC->SelectObject(m_pMask);
// Change the background to trans color
COLORREF clrSaveBk = pDC->SetBkColor(pFrame->m_dlgNewProject->m_dwTrans);
// This call sets up the mask bitmap.
//AfxMessageBox(L"Doing bitblt for mask");
pMaskDC->BitBlt(0,0,m_iTileW, m_iTileH, pDC,0,0,SRCCOPY);
COLORREF clrSaveDstText = pDC->SetTextColor(RGB(255,255,255));
pDC->SetBkColor(RGB(0,0,0));
pDC->BitBlt(0,0,m_iTileW, m_iTileW, pMaskDC,0,0,SRCAND);
// Clean up by deselecting any objects, and delete the
// DC's.
//AfxMessageBox(L"Cleaning up");
pMaskDC->SetTextColor(clrSaveDstText);
pDC->SetBkColor(clrSaveBk);
if (pPrevSource) pDC->SelectObject(pPrevSource);
if (pPrevMask) pMaskDC->SelectObject(pPrevMask);
delete pDC;
delete pMaskDC;
}
This is in part from code I found at http://www.codeproject.com/bitmap/transbitmapmask.asp
www.codeproject.com and www.codeguru.com are good sites for MFC and Windows programming.