Thread: transparentblt

  1. #1
    Registered User
    Join Date
    Dec 2005
    Location
    Canada
    Posts
    267

    Cool transparentblt

    i just thought some would find this link useful

    http://www.cppgames.com/forum/forum_...ID=73&get=last

    When ever I use the Windows API function TransparentBlt my compiler tells me it is undefined. I have msimg32.lib in my linker list. Does any one know how to fix this?
    To fix this just find your windows.h file and after the first block of code that ends with end if put this:



    #ifndef WINVER
    #define WINVER 0x0501
    #else
    #if defined(_WIN32_WINNT) && (WINVER < 0x0400) && (_WIN32_WINNT > 0x0400)
    #error WINVER setting conflicts with _WIN32_WINNT setting
    #endif
    #endif
    is this any better than putting
    Code:
    #define WINVER 0x0500
    before
    Code:
    #include <windows.h>
    ?

  2. #2
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    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.
    Last edited by VirtualAce; 09-13-2006 at 01:40 AM.

  3. #3
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Quote Originally Posted by h_howee
    s this any better than putting?
    Using the windows headers should hopefully offer some insight into and clarification of this issue.

    >>This is in part from code I found at<<

    The original transparent blitting technique was first described in this old msdn knowledge base article which is probably the precursor of all subsequent examples. This revised version describes the method but more succinctly.
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I got the idea from the old BASIC Put and Get doing the same thing but couldn't get it to work so I went with TransparentBlt. But I needed scaling support so did some searching on the net and after a couple of pages of google links finally found this.

    But yeah the article is on MSDN even though that one is a bit more confusing.

  5. #5
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    I think you should define 0x0501, not 0x0500, because the headers check, if the version is over 0x0500, but 0x0500 is not OVER 0x0500.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TransparentBlt()
    By SniperSAS in forum Windows Programming
    Replies: 6
    Last Post: 03-03-2006, 11:17 PM
  2. TransparentBlt error
    By jmd15 in forum Windows Programming
    Replies: 3
    Last Post: 08-29-2005, 08:22 PM
  3. TransparentBlt
    By rEtard in forum Windows Programming
    Replies: 2
    Last Post: 04-13-2005, 04:00 AM
  4. TransparentBlt
    By Trauts in forum Windows Programming
    Replies: 2
    Last Post: 02-27-2003, 07:40 PM