Problem drawing transparent bitmap using DrawTransparentBitmap exisitng ONLY in Win98 16bit color
-
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
-
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
-
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
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
-
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