[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Flicker free changing of images

Posted on 2005-04-28
12
Medium Priority
?
201 Views
Last Modified: 2008-01-09
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
Comment
Question by:stuartlandreth
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 8

Expert Comment

by:List244
ID: 13886151
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
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13886192
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 10

Expert Comment

by:fds_fatboy
ID: 13886961
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 13886990
And this one (which explains my previous link in more detail)
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 13887061
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
 

Author Comment

by:stuartlandreth
ID: 13925010
Thanks for all the links guys, but I can't grasp all the bitblt tutorials.
I just need a quickfix solution!
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13925728
Did you try the AutoRedraw property :)
0
 
LVL 23

Expert Comment

by:gecko_au2003
ID: 13925750
Take a look here :

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

Look at the first one which is called Paint Event.
0
 
LVL 8

Accepted Solution

by:
List244 earned 500 total points
ID: 13927531
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses
Course of the Month20 days, 10 hours left to enroll

868 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question