Painting using BitBlt


'Code By Kiran
'Painting a normal picture and a transparent picture using Bitblt API
'Constant Declarations
'Copies the source bitmap to destination bitmap

Public Const SRCCOPY = &HCC0020
'Combines pixels of the destination with source bitmap using the boolean AND operator.
Public Const SRCAND = &H8800C6
'Combines pixels of the destination with source bitmap using the boolean XOR operator.
Public Const SRCINVERT = &H660046
'Combines pixels of the destination with source bitmap using the boolean OR operator.
Public Const SRCPAINT = &HEE0086
'Inverts the destination bitmap and then combines the results with the source bitmap using the boolean AND operator.

Public Const SRCERASE = &H4400328
'Turns all output to white.
Public Const WHITENESS = &HFF0062
'Turns output to black.
Public Const BLACKNESS = &H42
'API Declarations
Public Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal X As Long, ByVal Y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long

'Painting picture from Picture2 to Picture1 (You can use diferent constants as per your requirements)
Dim RetVal as Long
RetVal = BitBlt(Picture1.hDC, 0, 0, 320, 200, Picture2.hDC, 0, 0, SRCCOPY)

'To paint transparent picture, you need to create two mask pictures, Picture2 and Picture3 one with white background another with black background
Dim RetVal as Long
RetVal = BitBlt(Picture1.hDC, 0, 0, 320, 200, Picture2.hDC, 0, 0, SRCAND)
RetVal = BitBlt(Picture1.hDC, 0, 0, 320, 200, Picture3.hDC, 0, 0, SRCPAINT)


You can view this article online at:
http://www.kiranreddys.com/knowledgebase/index.php/article/painting-using-bitblt