Results 1 to 6 of 6

Thread: prevent flashing when using BitBlt

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2000
    Location
    Galt, Ca
    Posts
    47

    Talking prevent flashing when using BitBlt

    i tried using Me.refresh after BitBlt to stop the flickering, but it doesn't work

    -emptywords

  2. #2
    AIS_DK
    Guest
    If you use BitBlt extensively, the best way to avoid flicker is to create a compatiblebitmap in memory, do all you drawing to this bitmaps, and then with one swoop BitBlt this bitmap on to the screen. This should pretty mush eliminate any flicker.

    If the flicker is caused by fast graphics (if you are making a game). I would suggest that you implement DirectX, since it's i created to render fast graphics.

  3. #3
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485

    Any Examples?

    Anyone have an example of this and/or explanation of how to use it? Please! I'm tired of drawing to 3 picture boxes at a time to mask, filter backcolor, and add to make transparentcies.

  4. #4
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    I did not notice any flickering but you can try the following code as an example of working with the memory DC and the memory bitmap:

    VB Code:
    1. Private 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
    2. Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
    3. Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
    4. Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
    5. Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
    6. Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source
    7.  
    8. Dim memdc As Long
    9. Dim membmp As Long
    10.  
    11.  
    12. Private Sub Command1_Click()
    13. 'create a memory DC for this form
    14. memdc = CreateCompatibleDC(Me.hdc)
    15. 'create a bitmap for this form
    16. membmp = CreateCompatibleBitmap(Me.hdc, Picture1.ScaleWidth, Picture1.ScaleHeight)
    17. 'select that bitmap into the memory dc
    18. SelectObject memdc, membmp
    19. 'paste the picture from the picture onto the memory DC.
    20. 'Because we selected the bitmap in the memory DC, it'll
    21. 'be pasted on the bitmap
    22. BitBlt memdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, SRCCOPY
    23. 'now paste the contents of the memory DC on this form
    24. BitBlt Me.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, memdc, 0, 0, SRCCOPY
    25.  
    26. End Sub
    27.  
    28. Private Sub Form_Unload(Cancel As Integer)
    29. DeleteObject memdc
    30. DeleteObject membmp
    31. End Sub

    Maybe you'll find some difference.
    Baaaaaaaaah

  5. #5
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    There are more people in the G&G forum that can help with this if need be, and any other graphics questions. They belong there more.

    But to add a little meat to this post, you can alternatively use another Picturebox for your "backbuffer". It can be invisible and autoredrawing, and then you would simply blit that onto the other picturebox. It's a bit more simple but will need more memory.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  6. #6
    Hyperactive Member
    Join Date
    Jun 1999
    Location
    ma,usa
    Posts
    485
    Thanks guys! I just wanted an example. I don't have the flickerring problem but appended to the thread for info on the function so I don't have to setup more than one picbox in design time for blitting known areas of the screen. Thanks!

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