Help Me on Transperency Options with BitBlt. Please do it step by step and not just post the code I need help. If I am to make a game I need transperency. Thanks
Printable View
Help Me on Transperency Options with BitBlt. Please do it step by step and not just post the code I need help. If I am to make a game I need transperency. Thanks
First, declare the Function and Consts in a module.
Now you need a Sprite and a Mask. The Sprite is the regular graphic (with a black background) and the Mask is a blackCode:Declare 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
Public Const SRCAND = &H8800C6
Public Const SRCCOPY = &HCC0020
Public Const SRCPAINT = &HEE0086
Public Const MERGEPAINT = &HBB0226
and white version. In the mask colour the background white and the picture black, regardless of the original colour.
Now, place the Mask and Sprite in 2 PictureBoxes. Call them picMask for the Mask and picSprite for the Sprite.
Now make a CommandButton on the Form and put the following code in it.
Let's analyzie this. The first argument is where you wantCode:Private Sub Command1_Click()
status = BitBlt(Form1.hDC, 0, 0, 50, 50, picMask.hDC, 0, 0, SRCAND)
status = BitBlt(Form1.hDC, 0, 0, 50, 50, picSprite.hDC, 0, 0, SRCPAINT)
End Sub
the image copied too (In this case it's Form1). The next 4
are the positions to copy, Left, Top, Width, Height. The
next is the source of the picture you are copying. The next
2 are the Left and Top positions of the of where you want
to copy from the source. We have already mentioned the Width
and Height so we can omit those. And lastly, there is the
OPCODE. It determins how you copy the picture. SRCAND copies
all but white. As you can see, we used this because we want
to copy only the black part of the Mask and omit the white
background (for transparency). The SRCPAINT copies all but
black. We used this when copying our sprite, because we
want all of the main picture, but omit the black background
(for transparency)
That's it. If you're wondering why we had to do the Mask and
the Sprite it's because since we do not copy the balck from
our Sprite, it's going to look watered down, so we have to
lay down the black part of the picture first, then copy the
rest of it.