PDA

Click to See Complete Forum and Search --> : BitBlt Problems...


CyberCarsten
Oct 25th, 2001, 02:18 PM
Hi guys!
I'm trying to move a picture using BitBlt to avoid flickering.

I have got the picture to move both to the left and to the right, but when it moves to the right, it leaves some kind of trail....why is that???

Also, how can make a picture transparent...meaning how do i only show, ie. if the picture is a ball, the ball and not the background??

Source:


Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Dim x As Integer

Private Sub Timer1_Timer()
If GetAsyncKeyState(vbKeyRight) Then
GoRight
End If
If GetAsyncKeyState(vbKeyLeft) Then
GoLeft
End If

End Sub

Public Sub GoRight()
x = x + 2
Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
Picture2.hDC, 0, 0, SRCcopy)
Picture1.Refresh


End Sub

Public Sub GoLeft()
x = x - 2
Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
Picture2.hDC, 0, 0, SRCcopy)
Picture1.Refresh

End Sub


Module:


' ********************************************************************
' Project : BitBltPrimer.vbp
' Filename : BitBlt.bas
' Description : BitBlt API primer tutorial project
' Created : 11.15 PM GMT + 10.00, February 23, 1998
' Modified : 12:26 AM GMT + 10.00, October 17, 1998
' ********************************************************************
' Author : Michael Lambino
' E-mail : ProSoft@the18th.com
' Comments : Copyright ©, 23 February, 1998, Michael Lambino
' License : Freeware - Freely distributable unmodified.
' : No costs may be charged whatsoever for the
' : distribution of this tutorial, in any form of
' : media, without expressed permission of the author.
' ********************************************************************

' Require all variables be declared.
Option Explicit

' Enumerated raster operation constants
Public Enum RasterOps
'
' Copies the source bitmap to destination bitmap
SRCcopy = &HCC0020
'
' Combines pixels of the destination with source bitmap using
' the Boolean AND operator.
SRCAND = &H8800C6
'
' Combines pixels of the destination with source bitmap using
' the Boolean XOR operator.
SRCinvert = &H660046
'
' Combines pixels of the destination with source bitmap using
' the Boolean OR operator.
SRCpaint = &HEE0086
'
' Inverts the destination bitmap and then combines the results
' with the source bitmap using the Boolean AND operator.
SRCERASE = &H4400328
'
' Turns all output white.
WHITENESS = &HFF0062
'
' Turn output black.
BLACKNESS = &H42
End Enum

' BitBlt API Public Declaration
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 RasterOps _
) As Long


' ********************************************************************
' Parameter descriptions
' ********************************************************************
' ByVal hDestDC As Long : hDC of object (Destination PictureBox hDC)
' : in which resulting Blt operation will
' : performed.
' ----------------------+---------------------------------------------
' ByVal x As Long : Leftmost coordinate (upper-left) of the
' : destination rectangle.
' ----------------------+---------------------------------------------
' ByVal y As Long : Topmost coordinate (upper-left) of the
' : destination rectangle.
' ----------------------+---------------------------------------------
' ByVal nWidth As Long : Width of the rectangle of the destination
' : image to be bltted.
' ----------------------+---------------------------------------------
' ByVal nHeight As Long : height of the rectangle of the destination
' : image to be bltted.
' ----------------------+---------------------------------------------
' ByVal hSrcDC As Long : hDC of object (Source PictureBox hDC) in
' : which resulting Blt operation will be
' : performed from.
' ----------------------+---------------------------------------------
' ByVal xSrc As Long : Leftmost coordinate (upper-left) of the
' : source rectangle.
' ----------------------+---------------------------------------------
' ByVal ySrc As Long : Topmost coordinate (upper-left) of the
' : source rectangle.
' ----------------------+---------------------------------------------
' ByVal dwRop As Long : specifies the raster operation to be
' : performed as above.
' --------------------------------------------------------------------

Gaming_World
Oct 25th, 2001, 03:31 PM
To remove the flicking, place the pictures a hidden back buffer, then bring them to the visible front buffer.

To do transperancy, use a mask and srcpaint instead of srccopy. I belive the mask needs to be white where you want transperancy, and black to show up. Paint the background, mask, then the sprite.

You should also clear the backbuffer after use. It must have autoredraw on, while the frontbuffer has it off.

PsychoMark
Oct 26th, 2001, 02:03 AM
...or simply set the picturebox's AutoRedraw property to True, call PicBox.Cls() before drawing and PicBox.Refresh() afterwards...

For the transparancy, just search these forums for BitBlt and Masks, you should find a lot of posts :)

Janus
Oct 26th, 2001, 03:17 AM
How it works:

SrcAnd the mask to the destination area.
The white areas are 255,255,255 - of course, Value And 255 = Value.
The black areas are 0,0,0, - of course, Value And 0 = 0.

SrcPaint the image to the destination area. The masked areas of the image MUST BE BLACK.
SrcPaint is essentially SrcOr. Stupid name.
The image is made up of various values. The mask you applied has already set all the areas covered by the image to black. - of course, Value Or 0 = Value.
The black areas are 0,0,0 - of course, Value Or 0 = Value, again.

CyberCarsten
Oct 26th, 2001, 05:50 AM
Thanks for all your replies! They really helped! :)

I just have another question: How can I make a picture move around using BitBlt??

PsychoMark
Oct 27th, 2001, 03:44 AM
Change the X and Y values for the BitBlt call :)

CyberCarsten
Oct 27th, 2001, 08:16 AM
I did, but it flickered, and I want to avoid that....any suggestions??

PsychoMark
Oct 27th, 2001, 10:05 AM
Take a look at my first reply :)