Archived

This topic is now archived and is closed to further replies.

displaying a graphic transparent...

This topic is 5588 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

	CDC *pDisplayMemDC = new CDC;
	CDC *pMaskDC = new CDC;
	CDC *pMemDC = new CDC;
	CBitmap *pBitmap = new CBitmap;
	CBitmap *pMaskBitmap = new CBitmap;
	CBitmap *pMemBitmap = new CBitmap;
	int cxLogo, cyLogo;
	BITMAP bm;

	pBitmap->LoadBitmap (ResNum);
	pDisplayMemDC->CreateCompatibleDC (dc);
	CBitmap *pOldBitmap = (CBitmap *)pDisplayMemDC->SelectObject (pBitmap);

	pBitmap->GetObject (sizeof(bm), &bm);
	cxLogo = bm.bmWidth;
	cyLogo = bm.bmHeight;

	pMaskBitmap->CreateBitmap (cxLogo, cyLogo, 1, 1, NULL);
	pMaskDC->CreateCompatibleDC (dc);
	CBitmap *pOldMask = (CBitmap *)pMaskDC->SelectObject (pMaskBitmap);
	COLORREF oldBkColor = pDisplayMemDC->SetBkColor (TRANSPARENT_COLOR);
	pMaskDC->BitBlt (0, 0, cxLogo, cyLogo, pDisplayMemDC, 0, 0, SRCCOPY);

	pMemBitmap->CreateCompatibleBitmap (dc, cxLogo, cyLogo);
	pMemDC->CreateCompatibleDC (dc);
	CBitmap *pOldMem = (CBitmap *)pMemDC->SelectObject (pMemBitmap);

	pMemDC->BitBlt (0, 0, cxLogo, cyLogo, dc,           0, 0, SRCCOPY);
	pMemDC->BitBlt (0, 0, cxLogo, cyLogo, pDisplayMemDC, 0, 0, SRCINVERT);
	pMemDC->BitBlt (0, 0, cxLogo, cyLogo, pMaskDC,       0, 0, SRCAND);
	pMemDC->BitBlt (0, 0, cxLogo, cyLogo, pDisplayMemDC, 0, 0, SRCINVERT);
	dc->BitBlt      (xPos, yPos, cxLogo, cyLogo, pMemDC,        0, 0, SRCCOPY);

	delete pMemDC->SelectObject (pOldMem);
	delete pMemDC;
	delete pMaskDC->SelectObject (pOldMask);
	delete pMaskDC;
	delete pDisplayMemDC->SelectObject (pOldBitmap);
	delete pDisplayMemDC;
 
This code makes images transparent. Using White so if the pixel is white its not displayed. My problem with the above is it only works for small pictures can anyone figure out what I am doing wrong??

Share this post


Link to post
Share on other sites