Thread: Transparency function not working

  1. #1

    Transparency function not working

    I am making a transparency function in GDI. The way it works is by making a mask image, which is a monochrome bitmap where all white areas is where the image is transparent and black where it is not. The color image's transparent color (this case 255,0,255) is set to black. The mask image is blitted to the window's DC, using the SRCAND (Boolean AND) raster operation, and then the color image is blitted on top of that using the SRCPAINT (Boolean OR) operation. Here is the code:

    Code:
    __declspec(dllexport) void
    _NebGDI::DrawSpriteEx(HBITMAP hbitmap, HDC hdcTarget, int X, int Y, DWORD dwRaster)
    {
      HBITMAP hbmMask;
      HDC hdcMem, hdcMem2;
      HBITMAP hbmOld, hbmOld2;
      BITMAP bmp;
    
      GetObject(hbitmap, sizeof(BITMAP), &bmp);
      hbmMask = CreateBitmap(bmp.bmWidth, bmp.bmHeight, 1,1, NULL);
    
      hdcMem = CreateCompatibleDC(0);
      hdcMem2= CreateCompatibleDC(0);
    
      hbmOld = (HBITMAP)SelectObject(hdcMem, hbitmap);
      hbmOld2= (HBITMAP)SelectObject(hdcMem2, hbmMask);
    
      SetBkColor(hdcMem, RGB(255,0,255));
    
      BitBlt(hdcMem2, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCCOPY);
      BitBlt(hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight, hdcMem2, 0, 0, SRCINVERT);
    
      SelectObject(hdcMem, hbmMask);
      BitBlt(hdcTarget, X, Y, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCAND);  
      SelectObject(hdcMem, hbitmap);
      BitBlt(hdcTarget, X, Y, bmp.bmWidth, bmp.bmHeight, hdcMem, 0, 0, SRCPAINT);
    
      SelectObject(hdcMem, hbmOld);
      SelectObject(hdcMem2, hbmOld2);
    
      DeleteDC(hdcMem);
      DeleteDC(hdcMem2);
      DeleteObject(hbmMask);
    }

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    I'd like to say, 'This question sounds like it belongs in the Game Programming forum', but you didn't really ask a question. So, think up a question and post it there. I think gfx questions are best handled there.
    FAQ

    "The computer programmer is a creator of universes for which he alone is responsible. Universes of virtually unlimited complexity can be created in the form of computer programs." -- Joseph Weizenbaum.

    "If you cannot grok the overall structure of a program while taking a shower, you are not ready to code it." -- Richard Pattis.

  3. #3
    oops. The question is, why isn't it working?

  4. #4
    I figured it out

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Undefined Reference Compiling Error
    By AlakaAlaki in forum C++ Programming
    Replies: 1
    Last Post: 06-27-2008, 11:45 AM
  2. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  3. C++ compilation issues
    By Rupan in forum C++ Programming
    Replies: 1
    Last Post: 08-22-2005, 05:45 AM
  4. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  5. I need help with passing pointers in function calls
    By vien_mti in forum C Programming
    Replies: 3
    Last Post: 04-24-2002, 10:00 AM