PDA

Click to See Complete Forum and Search --> : prevent flashing when using BitBlt


emptywords
May 23rd, 2001, 08:45 PM
i tried using Me.refresh after BitBlt to stop the flickering, but it doesn't work

-emptywords

AIS_DK
May 24th, 2001, 03:15 AM
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.

joey o.
Nov 30th, 2001, 08:34 AM
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.

abdul
Nov 30th, 2001, 06:44 PM
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:


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
Private Declare Function CreateCompatibleBitmap Lib "gdi32" (ByVal hdc As Long, ByVal nWidth As Long, ByVal nHeight As Long) As Long
Private Declare Function CreateCompatibleDC Lib "gdi32" (ByVal hdc As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function SelectObject Lib "gdi32" (ByVal hdc As Long, ByVal hObject As Long) As Long
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source

Dim memdc As Long
Dim membmp As Long


Private Sub Command1_Click()
'create a memory DC for this form
memdc = CreateCompatibleDC(Me.hdc)
'create a bitmap for this form
membmp = CreateCompatibleBitmap(Me.hdc, Picture1.ScaleWidth, Picture1.ScaleHeight)
'select that bitmap into the memory dc
SelectObject memdc, membmp
'paste the picture from the picture onto the memory DC.
'Because we selected the bitmap in the memory DC, it'll
'be pasted on the bitmap
BitBlt memdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, Picture1.hdc, 0, 0, SRCCOPY
'now paste the contents of the memory DC on this form
BitBlt Me.hdc, 0, 0, Picture1.ScaleWidth, Picture1.ScaleHeight, memdc, 0, 0, SRCCOPY

End Sub

Private Sub Form_Unload(Cancel As Integer)
DeleteObject memdc
DeleteObject membmp
End Sub


Maybe you'll find some difference.

Sastraxi
Nov 30th, 2001, 07:17 PM
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.

joey o.
Dec 1st, 2001, 12:43 PM
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!