Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Problem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color

Problem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color

Scheduled Pinned Locked Moved C / C++ / MFC
graphicshelp
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    lob
    wrote on last edited by
    #1

    Hello, I'm using following function : ----------------------------------------------------------------------- void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart, COLORREF cTransparentColor) { BITMAP bm; COLORREF cColor; HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave; POINT ptSize; hdcTemp = CreateCompatibleDC(hdc); SelectObject(hdcTemp, hBitmap); // Select the bitmap GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); ptSize.x = bm.bmWidth; // Get width of bitmap ptSize.y = bm.bmHeight; // Get height of bitmap DPtoLP(hdcTemp, &ptSize, 1); // Convert from device // to logical points // Create some DCs to hold temporary data. hdcBack = CreateCompatibleDC(hdc); hdcObject = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc); hdcSave = CreateCompatibleDC(hdc); // Create a bitmap for each DC. DCs are required for a number of // GDI functions. // Monochrome DC bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); // Monochrome DC bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); // Each DC must select a bitmap object to store pixel data. bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack); bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject); bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem); bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave); // Set proper mapping mode. SetMapMode(hdcTemp, GetMapMode(hdc)); // Save the bitmap sent here, because it will be overwritten. BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC to the color. // contained in the parts of the bitmap that should be transparent cColor = SetBkColor(hdcTemp, cTransparentColor); // Create the object mask for the bitmap by performing a BitBlt // from the source bitmap to a monochrome bitmap. BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the back

    L J 2 Replies Last reply
    0
    • L lob

      Hello, I'm using following function : ----------------------------------------------------------------------- void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart, COLORREF cTransparentColor) { BITMAP bm; COLORREF cColor; HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave; POINT ptSize; hdcTemp = CreateCompatibleDC(hdc); SelectObject(hdcTemp, hBitmap); // Select the bitmap GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); ptSize.x = bm.bmWidth; // Get width of bitmap ptSize.y = bm.bmHeight; // Get height of bitmap DPtoLP(hdcTemp, &ptSize, 1); // Convert from device // to logical points // Create some DCs to hold temporary data. hdcBack = CreateCompatibleDC(hdc); hdcObject = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc); hdcSave = CreateCompatibleDC(hdc); // Create a bitmap for each DC. DCs are required for a number of // GDI functions. // Monochrome DC bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); // Monochrome DC bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); // Each DC must select a bitmap object to store pixel data. bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack); bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject); bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem); bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave); // Set proper mapping mode. SetMapMode(hdcTemp, GetMapMode(hdc)); // Save the bitmap sent here, because it will be overwritten. BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC to the color. // contained in the parts of the bitmap that should be transparent cColor = SetBkColor(hdcTemp, cTransparentColor); // Create the object mask for the bitmap by performing a BitBlt // from the source bitmap to a monochrome bitmap. BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the back

      L Offline
      L Offline
      lob
      wrote on last edited by
      #2

      Any ideas ?

      1 Reply Last reply
      0
      • L lob

        Hello, I'm using following function : ----------------------------------------------------------------------- void DrawTransparentBitmap(HDC hdc, HBITMAP hBitmap, int xStart, int yStart, COLORREF cTransparentColor) { BITMAP bm; COLORREF cColor; HBITMAP bmAndBack, bmAndObject, bmAndMem, bmSave; HBITMAP bmBackOld, bmObjectOld, bmMemOld, bmSaveOld; HDC hdcMem, hdcBack, hdcObject, hdcTemp, hdcSave; POINT ptSize; hdcTemp = CreateCompatibleDC(hdc); SelectObject(hdcTemp, hBitmap); // Select the bitmap GetObject(hBitmap, sizeof(BITMAP), (LPSTR)&bm); ptSize.x = bm.bmWidth; // Get width of bitmap ptSize.y = bm.bmHeight; // Get height of bitmap DPtoLP(hdcTemp, &ptSize, 1); // Convert from device // to logical points // Create some DCs to hold temporary data. hdcBack = CreateCompatibleDC(hdc); hdcObject = CreateCompatibleDC(hdc); hdcMem = CreateCompatibleDC(hdc); hdcSave = CreateCompatibleDC(hdc); // Create a bitmap for each DC. DCs are required for a number of // GDI functions. // Monochrome DC bmAndBack = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); // Monochrome DC bmAndObject = CreateBitmap(ptSize.x, ptSize.y, 1, 1, NULL); bmAndMem = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); bmSave = CreateCompatibleBitmap(hdc, ptSize.x, ptSize.y); // Each DC must select a bitmap object to store pixel data. bmBackOld = (HBITMAP)SelectObject(hdcBack, bmAndBack); bmObjectOld = (HBITMAP)SelectObject(hdcObject, bmAndObject); bmMemOld = (HBITMAP)SelectObject(hdcMem, bmAndMem); bmSaveOld = (HBITMAP)SelectObject(hdcSave, bmSave); // Set proper mapping mode. SetMapMode(hdcTemp, GetMapMode(hdc)); // Save the bitmap sent here, because it will be overwritten. BitBlt(hdcSave, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the background color of the source DC to the color. // contained in the parts of the bitmap that should be transparent cColor = SetBkColor(hdcTemp, cTransparentColor); // Create the object mask for the bitmap by performing a BitBlt // from the source bitmap to a monochrome bitmap. BitBlt(hdcObject, 0, 0, ptSize.x, ptSize.y, hdcTemp, 0, 0, SRCCOPY); // Set the back

        J Offline
        J Offline
        John R Shaw
        wrote on last edited by
        #3

        All right I'll give you this one function, since it is in my list for posseble aticles to this site. (it is only a part of of the file - the MSDN has an aticle on this suject some where, not to mention the wwww) //////////////////////////////// // John R. Shaw (2001/03/23) // Transparent Blit for Windows 3.x and above ////////////////////////////////////////////////////////// BOOL TransBitBlt( HDC hdcDest, // handle to destination DC int nXOriginDest, // x-coord of destination upper-left corner int nYOriginDest, // y-coord of destination upper-left corner int nWidthDest, // width of destination rectangle int hHeightDest, // height of destination rectangle HDC hdcSrc, // handle to source DC int nXOriginSrc, // x-coord of source upper-left corner int nYOriginSrc, // y-coord of source upper-left corner int nWidthSrc, // width of source rectangle int nHeightSrc, // height of source rectangle UINT crTransparent // color to make transparent ) { // Win 98 and above if( g_TransBlt.DrawTransparent( hdcDest, nXOriginDest, nYOriginDest, nWidthDest, hHeightDest, hdcSrc , nXOriginSrc , nYOriginSrc , nWidthSrc , nHeightSrc, crTransparent) ) { return TRUE; } // Win 3.x and above // Note: This technique may not necessarily work on printer devices. // Create temporary DCs HDC hdcTemp = CreateCompatibleDC(hdcDest); if( hdcTemp == NULL ) return FALSE; HDC hdcMask = CreateCompatibleDC(hdcDest); if( hdcTemp == NULL ) { DeleteDC(hdcTemp); return FALSE; } // Create temporary Bitmaps HBITMAP hBmpMask = CreateBitmap(nWidthSrc,nHeightSrc,1,1,NULL); if( hBmpMask == NULL ) { DeleteDC(hdcMask); DeleteDC(hdcTemp); return FALSE; } HBITMAP hBmpTemp = CreateCompatibleBitmap(hdcDest,nWidthSrc,nHeightSrc); if( hBmpTemp == NULL ) { DeleteObject(hBmpTemp); DeleteDC(hdcMask); DeleteDC(hdcTemp); return FALSE; } HGDIOBJ hOldBmpMask = SelectObject(hdcMask,HGDIOBJ(hBmpMask)); // Use temporary DC to reduce flicker HGDIOBJ hOldBmpTemp = SelectObject(hdcTemp,HGDIOBJ(hBmpTemp)); if( BitBlt(hdcTemp,0, 0, nWidthSrc,nHeightSrc, hdcDest, nXOriginDest, nYOriginDest, SRCCOPY) ) { // If we made it here there should be no more possible problems // Create mask using crTransparent COLORREF OldBkColor = SetBkColor(hdcSrc,crTransparent); BitBlt(hdcMask,0, 0, nWidthSrc,nHeightSrc,hdcSrc, nXOriginSrc,nYOriginSrc, SRCCOPY); SetBkColor(hdcTemp,OldBkColor); // Draw

        L 1 Reply Last reply
        0
        • J John R Shaw

          All right I'll give you this one function, since it is in my list for posseble aticles to this site. (it is only a part of of the file - the MSDN has an aticle on this suject some where, not to mention the wwww) //////////////////////////////// // John R. Shaw (2001/03/23) // Transparent Blit for Windows 3.x and above ////////////////////////////////////////////////////////// BOOL TransBitBlt( HDC hdcDest, // handle to destination DC int nXOriginDest, // x-coord of destination upper-left corner int nYOriginDest, // y-coord of destination upper-left corner int nWidthDest, // width of destination rectangle int hHeightDest, // height of destination rectangle HDC hdcSrc, // handle to source DC int nXOriginSrc, // x-coord of source upper-left corner int nYOriginSrc, // y-coord of source upper-left corner int nWidthSrc, // width of source rectangle int nHeightSrc, // height of source rectangle UINT crTransparent // color to make transparent ) { // Win 98 and above if( g_TransBlt.DrawTransparent( hdcDest, nXOriginDest, nYOriginDest, nWidthDest, hHeightDest, hdcSrc , nXOriginSrc , nYOriginSrc , nWidthSrc , nHeightSrc, crTransparent) ) { return TRUE; } // Win 3.x and above // Note: This technique may not necessarily work on printer devices. // Create temporary DCs HDC hdcTemp = CreateCompatibleDC(hdcDest); if( hdcTemp == NULL ) return FALSE; HDC hdcMask = CreateCompatibleDC(hdcDest); if( hdcTemp == NULL ) { DeleteDC(hdcTemp); return FALSE; } // Create temporary Bitmaps HBITMAP hBmpMask = CreateBitmap(nWidthSrc,nHeightSrc,1,1,NULL); if( hBmpMask == NULL ) { DeleteDC(hdcMask); DeleteDC(hdcTemp); return FALSE; } HBITMAP hBmpTemp = CreateCompatibleBitmap(hdcDest,nWidthSrc,nHeightSrc); if( hBmpTemp == NULL ) { DeleteObject(hBmpTemp); DeleteDC(hdcMask); DeleteDC(hdcTemp); return FALSE; } HGDIOBJ hOldBmpMask = SelectObject(hdcMask,HGDIOBJ(hBmpMask)); // Use temporary DC to reduce flicker HGDIOBJ hOldBmpTemp = SelectObject(hdcTemp,HGDIOBJ(hBmpTemp)); if( BitBlt(hdcTemp,0, 0, nWidthSrc,nHeightSrc, hdcDest, nXOriginDest, nYOriginDest, SRCCOPY) ) { // If we made it here there should be no more possible problems // Create mask using crTransparent COLORREF OldBkColor = SetBkColor(hdcSrc,crTransparent); BitBlt(hdcMask,0, 0, nWidthSrc,nHeightSrc,hdcSrc, nXOriginSrc,nYOriginSrc, SRCCOPY); SetBkColor(hdcTemp,OldBkColor); // Draw

          L Offline
          L Offline
          lob
          wrote on last edited by
          #4

          John, Thanks , but your answer isn't answering my question. I do know how works TransparentBlt function , i asked what's wrong in my function for drawing transparent BITMAPS.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups