RE: What is the fastest method to switch picture files to produce animation
From: Santhosh Kutty (sakutty_at_online.microsoft.com)
Date: 06/09/04
- Next message: J French: "Re: Replacement for OpenComm CloseComm etc"
- Previous message: J French: "Re: Visual Basic for Autorun?"
- In reply to: Peter McLennan: "What is the fastest method to switch picture files to produce animation"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 09 Jun 2004 07:37:39 GMT
I checked through several resources to get you an answer on this. My
thoughts on this are several and I add comments from articles I found. I've
tested the code enclosed below as well. Because of the graphical nature of
Microsoft Windows, the speed of graphics and other display operations is
crucial to the perceived speed of the application. The faster forms appear
and paint, the faster your application will seem to the user. There are
several techniques you can use to speed up the apparent speed of your
application, including:
Set the ClipControls property of containers to False.
Use AutoRedraw appropriately.
Use image controls instead of picture box controls.
Hide controls when setting properties to avoid multiple repaints.
Use Line instead of PSet.
Set the ClipControls Property of Containers to False
Unless you are using graphics methods (Line, PSet, Circle, and Print), you
should set ClipControls to False for the form and for all frame and picture
box controls (it may cause unpredictable results if your code includes
graphics methods that draw behind other controls). When ClipControls is
False, Visual Basic doesnt overpaint controls with the background before
repainting the controls themselves. On forms that contain a lot of
controls, the resulting speed improvements are significant.
Use AutoRedraw Appropriately
When AutoRedraw is set to True for a form or control, Visual Basic
maintains a bitmap to repaint that form or control. Although this improves
the speed of simple repaints (for example, when the form or control is
revealed after a window that covers it is removed), it slows graphics
methods. Visual Basic has to perform the graphics methods on the AutoRedraw
bitmap and then copy the entire bitmap to the screen. This process also
consumes a considerable amount of memory.
If your application generates complex graphics but doesnt change them
frequently, setting AutoRedraw to True is appropriate. But if your
application draws graphics that must change frequently, you will get better
performance if you set AutoRedraw to False and perform the graphics methods
for the form or control in the Paint event.
Use Image Controls Instead of Picture Box Controls
This optimization improves the speed and minimizes the size of your
application; use it whenever possible. When you are simply displaying
pictures and reacting to click events and mouse actions on them, use the
image control instead of the picture box. Dont use a picture box unless you
need the capabilities only the picture box provides, such as graphics
methods, the ability to contain other controls, or dynamic data exchange
(DDE).
Hide Controls When Setting Properties to Avoid Multiple Repaints
Every repaint is expensive. The fewer repaints Visual Basic must perform,
the faster your application will appear. One way to reduce the number of
repaints is to make controls invisible while you are manipulating them. For
example, suppose you want to resize several list boxes in the Resize event
for the form:
Sub Form_Resize ()
Dim i As Integer, sHeight As Integer
sHeight = ScaleHeight / 4
For i = 0 To 3
lstDisplay(i).Move 0, i * sHeight, _
ScaleWidth, sHeight
Next
End Sub
This creates four separate repaints, one for each list box. You can reduce
the number of repaints by placing all the list boxes within a picture box,
and hiding the picture box before you move and size the list boxes. Then,
when you make the picture box visible again, all of the list boxes are
painted in a single pass:
Sub Form_Resize ()
Dim i As Integer, sHeight As Integer
picContainer.Visible = False
picContainer.Move 0, 0, ScaleWidth, ScaleHeight
sHeight = ScaleHeight / 4
For i = 0 To 3
lstDisplay(i).Move 0, i * sHeight, _
ScaleWidth, sHeight
Next
picContainer.Visible = True
End Sub
Note that this example uses the Move method instead of setting the Top and
Left properties. The Move method sets both properties in a single
operation, saving additional repaints.
Use Line Instead of PSet
The Line method is faster than a series of PSet methods. Avoid using the
PSet method and batch up the points into a single Line method. Shape and
line controls are appropriate for simple graphical elements that rarely
change; complex graphics, or graphics that change rapidly, are generally
best handled with graphics methods.
Outside of all this, the only crunch would be your resources and otherwise
you're good to go. I hope this answers your question.
Best regards,
Santhosh James Kutty
Microsoft Partner Support Engineer
This posting is provided “AS IS” with no warranties, and confers no rights.
Get Secure! - www.microsoft.com/security
- Next message: J French: "Re: Replacement for OpenComm CloseComm etc"
- Previous message: J French: "Re: Visual Basic for Autorun?"
- In reply to: Peter McLennan: "What is the fastest method to switch picture files to produce animation"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|