• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 204
  • Last Modified:

Flicker free changing of images

This is part of a happy hour button machine where each offer lights up in turn

I have loaded the relevant ON and OFF states into image controls stacked on top of each other with the ON state in front.
The graphics are transparant gif's because they are circular. However, there is a noticable white flicker in the transparant area as each one changes.

I have read about off-screen buffers and API but it seems very confusing. Here is the code I have at the minute.

Sub MoveRandom()
    Dim rn As Integer
    imgOfferOn(Position).Visible = False
    '
    Do
        rn = 1 + Int(Rnd * iNumOffers)
    Loop Until Position <> rn
    '
    Position = rn
    imgOfferOn(Position).Visible = True
End Sub


I have also tried doing it like this......


Sub MoveRandom()
    Dim rn As Integer
    imgOffer(Position).Picture= imgOfferOff(Position).Picture
    '
    Do
        rn = 1 + Int(Rnd * iNumOffers)
    Loop Until Position <> rn
    '
    Position = rn
    imgOfferOn(Position).Picture=imgOfferOn(Position).Picture
End Sub

but the flicker is still there.

Any help appreciated!!!

0
Stuart Landreth
Asked:
Stuart Landreth
  • 4
  • 3
  • 2
  • +1
1 Solution
 
List244Commented:
The property is called AutoRedraw. This forces the image not to redraw unless necessary.
Often times this means you may have to do Picture.REFRESH in order for it to redraw.
It prevents flickering by allowing it to draw when FINISHED, and not before. Another
thing to take a look into is BITBLT:

http://www.rookscape.com/vbgaming/GBeebe/bitblt.php

With bitblt you can copy images from one location and place them on another flicker
free.
0
 
Shane Russell2nd Line Desktop SupportCommented:
Yeah thats correct ! The PAQ's and the first URL go through all of the things with regards to flicker free animation / images. One of those things included in there was with regards to the bitblt :)

Anyway I hope our info helps you out !
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
fds_fatboyCommented:
And this one (which explains my previous link in more detail)
0
 
fds_fatboyCommented:
Whoops forgot to paste the link in:

http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_21349324.html

Both of these examples use double buffering and bitblt to provide flicker free animation.

The way double buffering works, is that you do all your drawing on an invisible virtual picture (your back buffer) When you have finished manipulating your frame, you replace the visible image with your backbuffer image in one memory operation (blt - or blit) thereby eliminating the flicker. As soon as you have done this, you start building the next frame in memory and repeat...
0
 
Stuart LandrethAuthor Commented:
Thanks for all the links guys, but I can't grasp all the bitblt tutorials.
I just need a quickfix solution!
0
 
Shane Russell2nd Line Desktop SupportCommented:
Did you try the AutoRedraw property :)
0
 
Shane Russell2nd Line Desktop SupportCommented:
Take a look here :

http://www.officecomputertraining.com/vbtutorial/tutpages/page27.asp

Look at the first one which is called Paint Event.
0
 
List244Commented:
Bitblt is very simple, you want to copy a picture right?

Private Declare Function BitBlt Lib "gdi32" Alias "BitBlt" (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


HdestDC - The Hdc of where you are copying the picture to. Ex: form1.hdc
X - Where to start copying the picture to on the X axis
Y - Where to start copying the picture to on the Y axis
nWidth - The width of the picture (The picture box should have autoredraw set to true, and scalemode to 3) ex : Picture1.Scalewidth
nHeight - The height of the picture (The picture box should have autoredraw set to true, and scalemode to 3) ex : Picture1.Scaleheight
hSrcDC - The Hdc of the picture you are copying. Ex: Picture1.hdc
xSrc - The start of where you want to copy the picture (normally 0)
ySrc - The start of where you want to copy the picture (normally 0)
dwRop - For simply copying a picture, this will be VbSrcCopy

Example of use:

Bitblt Form1.Hdc, 100,100,Picture1.scalewidth,Picture1.ScaleHeight,Picture1.Hdc,0,0,VbSrcCopy

That would copy Picture1 to form1.hdc. It would place the picture on the form at (100,100)

Putting it into a function for easy access:

Public sub CopyPicture (ToHDC as long, FromHDC as long,X as long, Y as long,PWidth as long,PHeight as long)
   Bitblt ToHDC,X,Y,PWidth,PHeight,FromHDC,0,0,VbSrcCopy
end sub

Using that function:

ToHDC - the HDC of the object you are copying to
FromHDC - the HDC  of the object you are copying from
X - x location of where the picture should go
Y - y location of where the picture should go
Pwidth - Width of the picture (PictureName.Scalewidth)
Pheight - Width of the picture (PictureName.Scaleheight)


The idea of flickerless movement:

Autoredraw = true (that is important more important than bitblt)
Scalemode = 3 (Just best to do that when working with graphics)

The idea is to draw everything to the form, before refreshing. Autoredraw
is what allows us to do this. We can clear the form, draw to it, then show it.
So the user sees a quick transition, and nothing else.

Example:

Public sub blah ()
Form1.cls ' Clear it
'DO drawing here
''
''
form1.refresh
end sub

A function like the above will allow for flickerless drawing. You clear the form, draw everything you
need on it, then refresh.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now