Results 1 to 8 of 8

Thread: BitBlt Problems...

  1. #1

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544

    BitBlt Problems...

    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:

    VB Code:
    1. Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
    2. Dim x As Integer
    3.  
    4. Private Sub Timer1_Timer()
    5. If GetAsyncKeyState(vbKeyRight) Then
    6.     GoRight
    7. End If
    8. If GetAsyncKeyState(vbKeyLeft) Then
    9.     GoLeft
    10. End If
    11.  
    12. End Sub
    13.  
    14. Public Sub GoRight()
    15. x = x + 2
    16.     Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
    17.     Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
    18.     Picture2.hDC, 0, 0, SRCcopy)
    19.     Picture1.Refresh
    20.      
    21.    
    22. End Sub
    23.  
    24. Public Sub GoLeft()
    25. x = x - 2
    26.     Call BitBlt(Picture1.hDC, x, 0, Picture2.ScaleWidth \ Screen.TwipsPerPixelX, _
    27.     Picture2.ScaleHeight \ Screen.TwipsPerPixelY, _
    28.     Picture2.hDC, 0, 0, SRCcopy)
    29.     Picture1.Refresh
    30.  
    31. End Sub

    Module:

    VB Code:
    1. ' ********************************************************************
    2. ' Project       :   BitBltPrimer.vbp
    3. ' Filename      :   BitBlt.bas
    4. ' Description   :   BitBlt API primer tutorial project
    5. ' Created       :   11.15 PM GMT + 10.00, February 23, 1998
    6. ' Modified      :   12:26 AM GMT + 10.00, October 17, 1998
    7. ' ********************************************************************
    8. ' Author        :   Michael Lambino
    9. ' E-mail        :   [email][email protected][/email]
    10. ' Comments      :   Copyright ©, 23 February, 1998, Michael Lambino
    11. ' License       :   Freeware - Freely distributable unmodified.
    12. '               :   No costs may be charged whatsoever for the
    13. '               :   distribution of this tutorial, in any form of
    14. '               :   media, without expressed permission of the author.
    15. ' ********************************************************************
    16.  
    17. ' Require all variables be declared.
    18.     Option Explicit
    19.  
    20. ' Enumerated raster operation constants
    21.     Public Enum RasterOps
    22.         '
    23.         ' Copies the source bitmap to destination bitmap
    24.         SRCcopy = &HCC0020
    25.         '
    26.         ' Combines pixels of the destination with source bitmap using
    27.         ' the Boolean AND operator.
    28.         SRCAND = &H8800C6
    29.         '
    30.         ' Combines pixels of the destination with source bitmap using
    31.         ' the Boolean XOR operator.
    32.         SRCinvert = &H660046
    33.         '
    34.         ' Combines pixels of the destination with source bitmap using
    35.         ' the Boolean OR operator.
    36.         SRCpaint = &HEE0086
    37.         '
    38.         ' Inverts the destination bitmap and then combines the results
    39.         ' with the source bitmap using the Boolean AND operator.
    40.         SRCERASE = &H4400328
    41.         '
    42.         ' Turns all output white.
    43.         WHITENESS = &HFF0062
    44.         '
    45.         ' Turn output black.
    46.         BLACKNESS = &H42
    47.     End Enum
    48.  
    49. ' BitBlt API Public Declaration
    50.     Declare Function BitBlt Lib "gdi32" ( _
    51.         ByVal hDestDC As Long, _
    52.         ByVal x As Long, _
    53.         ByVal y As Long, _
    54.         ByVal nWidth As Long, _
    55.         ByVal nHeight As Long, _
    56.         ByVal hSrcDC As Long, _
    57.         ByVal xSrc As Long, _
    58.         ByVal ySrc As Long, _
    59.         ByVal dwRop As RasterOps _
    60.         ) As Long
    61.  
    62.  
    63. ' ********************************************************************
    64. ' Parameter descriptions
    65. ' ********************************************************************
    66. ' ByVal hDestDC As Long :   hDC of object (Destination PictureBox hDC)
    67. '                       :   in which resulting Blt operation will
    68. '                       :   performed.
    69. ' ----------------------+---------------------------------------------
    70. ' ByVal x As Long       :   Leftmost coordinate (upper-left) of the
    71. '                       :   destination rectangle.
    72. ' ----------------------+---------------------------------------------
    73. ' ByVal y As Long       :   Topmost coordinate (upper-left) of the
    74. '                       :   destination rectangle.
    75. ' ----------------------+---------------------------------------------
    76. ' ByVal nWidth As Long  :   Width of the rectangle of the destination
    77. '                       :   image to be bltted.
    78. ' ----------------------+---------------------------------------------
    79. ' ByVal nHeight As Long :   height of the rectangle of the destination
    80. '                       :   image to be bltted.
    81. ' ----------------------+---------------------------------------------
    82. ' ByVal hSrcDC As Long  :   hDC of object (Source PictureBox hDC) in
    83. '                       :   which resulting Blt operation will be
    84. '                       :   performed from.
    85. ' ----------------------+---------------------------------------------
    86. ' ByVal xSrc As Long    :   Leftmost coordinate (upper-left) of the
    87. '                       :   source rectangle.
    88. ' ----------------------+---------------------------------------------
    89. ' ByVal ySrc As Long    :   Topmost coordinate (upper-left) of the
    90. '                       :   source rectangle.
    91. ' ----------------------+---------------------------------------------
    92. ' ByVal dwRop As Long   :   specifies the raster operation to be
    93. '                       :   performed as above.
    94. ' --------------------------------------------------------------------
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  2. #2
    Fanatic Member
    Join Date
    Oct 2000
    Location
    Oregon
    Posts
    962
    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.
    Involved in: Sentience

  3. #3
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    ...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
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  4. #4
    Addicted Member Janus's Avatar
    Join Date
    Aug 2001
    Location
    California
    Posts
    221
    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.
    "1 4m 4 1337 #4xz0r!'
    Janus

  5. #5

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    Thanks for all your replies! They really helped!

    I just have another question: How can I make a picture move around using BitBlt??
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  6. #6
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Change the X and Y values for the BitBlt call
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

  7. #7

    Thread Starter
    Frenzied Member CyberCarsten's Avatar
    Join Date
    Sep 1999
    Location
    Aalborg Ø, Denmark
    Posts
    1,544
    I did, but it flickered, and I want to avoid that....any suggestions??
    razor
    Software Engineer Student, Aalborg University, Denmark
    http://www.cs.auc.dk

    My email at AUC: will get a new email soon
    My website: http://www.razorsoftware.net


    Windows XP Pro/ Gentoo Linux (Laptop)
    Windows XP Pro (Home PC)

  8. #8
    Fanatic Member PsychoMark's Avatar
    Join Date
    Feb 2001
    Location
    Netherlands
    Posts
    540
    Take a look at my first reply
    Teaudirenopossum.Musasapientumfixaestinaure.
    (I can't hear you. There's a banana in my ear)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width