Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

bitblt flickering problem

Status
Not open for further replies.

mookie0001

Technical User
Jun 14, 2002
23
US
Hi everyone,

I am trying to smoothly scroll a VERY large image across a form. Unfortunately, I am getting very bad flickering problems. One helpful person recommended that I blit only the screen size instead of the entire picture. Unfortunately, I followed a tutorial to get this far and do not quite understand how I would go about doing this. Can someone give me a few pointers on this, or recommend other ways to stop the flickering (code snippets would be helpful). Thanks in advance!

-Chris


Here is my current source code:

Dim gameboard_image As New Bitmap("e:\hugePicture.jpg")

'Create the target graphics and get an hDC from it
Dim formGraphics As Graphics = Me.CreateGraphics()
Dim targethDC As IntPtr = formGraphics.GetHdc()

'Create an offscreen dc and select our bitmap in to it
Dim offscreenhDC As IntPtr = CreateCompatibleDC(targethDC)
Dim oldObject As IntPtr = SelectObject(offscreenhDC, gameboard_image.GetHbitmap())


Private Sub form2_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles MyBase.Paint

BitBlt(targethDC, m_dragOffset.X, m_dragOffset.Y, gameboard_image.Width, gameboard_image.Height, offscreenhDC, 0, 0, SRCCOPY)

End Sub
 
Hi Chris,

Try "double buffering", (at least I think that's what it's called!) It's very similar to what you've got above.

You need to create an off-screen DC the size of your drawing surface (let's say, the form) and blit your image to that in it's starting position. (don't forget the SelectObject, etc - but it looks like you're OK with all that stuff)

1. Blit the whole thing to your form's DC.
2. Clear the off-screen DC.
3. Blit the image to your off-screen DC in the next position.
4. Blit the whole thing to your form's DC, again. Etc, etc.

It should appear flickerless - let me know if you want me to stick some code together for you.

Hope it helps,
Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top