Code: Select all
; For drawing the image "as is":
Procedure DrawTransparentImage(DC, ImageID, x, y, TransparentColor) ;Draw Transparent Image
Protected ImageList, BM.BITMAP
GetObject_(ImageID,SizeOf(BITMAP),BM.BITMAP)
ImageID = CopyImage_(ImageID,#IMAGE_BITMAP,BM\bmWidth,BM\bmHeight,0)
ImageList = ImageList_Create_(BM\bmWidth,BM\bmHeight,#ILC_COLORDDB|#ILC_MASK,1,0)
ImageList_AddMasked_(ImageList,ImageID,TransparentColor)
ImageList_Draw_(ImageList,0,DC,x,y,#ILD_TRANSPARENT)
ImageList_Destroy_(ImageList)
DeleteObject_(ImageID)
EndProcedure
; For drawing and sizing the image:
ProcedureDLL DrawTransparentImageEx(DC, Bitmap, x, y, Width, Height, TransparentColor)
maskDC = CreateCompatibleDC_(DC)
tempDC = CreateCompatibleDC_(DC)
SourceDC = CreateCompatibleDC_(DC)
SelectObject_(SourceDC, Bitmap)
hMaskBmp = CreateBitmap_(Width, Height, 1, 1, 0)
hTempBmp = CreateCompatibleBitmap_(DC, Width, Height)
SelectObject_(maskDC, hMaskBmp)
SelectObject_(tempDC, hTempBmp)
TransparentColor= SetBkColor_(SourceDC, TransparentColor)
BitBlt_ (maskDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
SetBkColor_(SourceDC, TransparentColor)
BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #SRCCOPY)
BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #MERGEPAINT)
BitBlt_ (maskDC, 0, 0, Width, Height, maskDC, 0, 0, #NOTSRCCOPY)
BitBlt_ (tempDC, 0, 0, Width, Height, SourceDC, 0, 0, #SRCCOPY)
BitBlt_ (tempDC, 0, 0, Width, Height, maskDC, 0, 0, #MERGEPAINT)
BitBlt_ (DC, X, Y, Width, Height, tempDC, 0, 0, #SRCAND)
DeleteObject_ (hMaskBmp)
DeleteObject_ (hTempBmp)
DeleteDC_ (maskDC)
DeleteDC_ (tempDC)
DeleteDC_ (SourceDC)
EndProcedure
; To use these routines you need the device context (DC)
; You can get this easily with DC = StartDrawing(... etc.