RGB(128,128,128) -> COLOR_3DSHADOW
RGB(192,192,192) -> COLOR_3DFACE
RGB(223,223,223) -> COLOR_3DLIGHT
There are two problems:
1) it's not allowed to use this option for bitmaps with a color depth greater than 8bpp.
2) Windows makes "transparent" any point with Gray (Ltgray/DkGray) color. Actually similar points could be a part of picture.
I use for background unique color (different, depends of picture).
After ordinary LoadBitmap I call something like below to replace colors.
PixelX & PixelY defines position of one transparent pixel (typically, 0, 0)
Code:
Function AdaptBmp (hBmp As Dword, PixelX As Long, PixelY As Long) As Long Dim bm As BITMAP, hDC As Long, hMem1DC As Long, hMem2DC As Long, hMemBmp As Long, _ bmi As BITMAPINFO, i As Long, j As Long, m As Long, t As Long, tt As Long hDC = GetDC(0) hMem1DC = CreateCompatibleDC (hDC) hMem2DC = CreateCompatibleDC (hDC) ReleaseDC 0, hDC GetObject hBmp, SizeOf(bm), bm bmi.bmiHeader.biSize = SizeOf(bmi.bmiHeader) bmi.bmiHeader.biWidth = bm.bmWidth bmi.bmiHeader.biHeight = bm.bmHeight bmi.bmiHeader.biPlanes = 1 bmi.bmiHeader.biBitCount = 32 bmi.bmiHeader.biCompression = %BI_RGB hMemBmp = CreateDIBSection(hMem2DC, bmi, %DIB_RGB_COLORS, 0, 0, 0) GetObject hMemBmp, SizeOf(bm), bm SelectObject hMem1DC, hBmp SelectObject hMem2DC, hMemBmp BitBlt hMem2DC, 0, 0, bm.bmWidth, bm.bmHeight, hMem1Dc, 0, 0, %SRCCOPY t = GetSysColor(%COLOR_BTNFACE) ReDim b(3) As Byte At VarPtr(t) m = Rgb(b(2), b(1), b(0)) ReDim Ar(0) As Long At bm.bmBits t = (Ar((bm.bmHeight - 1 - PixelY) * bm.bmWidth + PixelX) And &HFFFFFF) For j = 0 To bm.bmHeight - 1 For i = 0 To bm.bmWidth - 1 If (Ar(tt) And &HFFFFFF) = t Then Ar(tt) = m Incr tt Next Next DeleteDC hMem1DC: DeleteDC hMem2DC: DeleteObject hBmp hBmp = hMemBmp: Function = hBmp End Function
------------------
E-MAIL: [email protected]
Leave a comment: