Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Greating a smooth moving image

4 views
Skip to first unread message

R. Hoek

unread,
Sep 1, 2003, 4:13:24 AM9/1/03
to
In the about dialog box of out application we would like to show a moving
image.
I've tried this, but it just flashes when I move the image.
Is there a better way to do this, then just moving a TImage across the
screen?
I'd rather not use someting like DirectX.

--
Greatings,

Ronald Hoek

Application developper
ComponentAgro B.V.
Barendrecht

Phone. +31-180-621306
Fax. +31-180-611797

mailto:ho...@componentagro.nl
http://www.componentagro.nl

Antti Piirainen

unread,
Sep 1, 2003, 4:34:25 AM9/1/03
to
R. Hoek wrote:

> In the about dialog box of out application we would like to show a moving
> image. I've tried this, but it just flashes when I move the image.

As a quick hack, try setting the value of the image's parent control's
DoubleBuffered (run-time) property to True. This works for TForm
descendants, for example. It removes the flashing, but not the jerking,
since this would require synchronization to the monitor's refresh rate.
No idea on how to accomplish that outside of DirectX :(

--
Antti Piirainen
Software Engineer, Camline Corporation (http://www.camline.fi/)
Mobile: +358-40-5222772 | Fax: +358-5-6214242

Danny Thorpe

unread,
Sep 1, 2003, 4:03:35 PM9/1/03
to
Don't move a control to achieve the effect of image movement. When you move
a control, the parent control behind it must be redrawn to erase where the
control used to be, then the control is redrawn in its new location. This
creates visible flicker.

Create a background bitmap the size of the control you'll be drawing on.
Copy the background of the control you will be drawing on into this
background bitmap (draw the control onto the background bitmap canvas).

Create an intermediate bitmap and set its width and height to the maximum
distance the image will move between redraws, plus the size of the image
itself.

Each time you move the image and need to repaint the image on the
destination (control or form) canvas, follow these steps:

1. Calculate the new location rect of the image

2. Calculate the union of the old image rect and the new image rect. This
is the update rect.

3. Copy the update rect area from the background bitmap to the intermediate
bitmap at coordinate 0,0. This will erase the old image from the
destination in the last step.

4. Draw the image on the intermediate bitmap. You'll need to subtract the
update rect's origin from the new image rect origin to place the image in
the right location in the intermediate bitmap. (If the new image rect is in
the top left corner of the update rect, draw the image at 0,0 in the
intermediate bitmap. etc)

5. Finally, draw the intermediate bitmap onto the destination canvas at the
update rect location. This will erase the old image and draw the new image
in one blit operation, eliminating flicker.

All bitmaps should be set to match the screen pixel format.

You will have to decide what time interval is appropriate to redraw the
image. You should probably use a timer message, as a continuous loop would
run too fast and take up too much CPU time. Since most monitors refresh the
screen between 60 and 90 times per second, there's not much need to run the
refresh timer much faster than that.

-Danny

Gordon Whittam

unread,
Sep 1, 2003, 7:03:37 PM9/1/03
to
In article <3f52ff70$1...@newsgroups.borland.com>, R. Hoek wrote:
> In the about dialog box of out application we would like to show a moving
> image.
> I've tried this, but it just flashes when I move the image.
> Is there a better way to do this, then just moving a TImage across the
> screen?
> I'd rather not use someting like DirectX.
>

There's a nice example of using clipping regions for fast drawing an Earl
Glynn's site. Go to
http://www.efg2.com/Lab/Library/Delphi/Graphics/Algorithms.htm and search
for Prilutsky.

Gordon


Nils Haeck

unread,
Sep 1, 2003, 7:27:27 PM9/1/03
to
Can you post your current code, so we can try to help you more in detail?

There were some good suggestions already:

1) Set "doublebuffered" to true

2) Do not use a fully windowed control, but rather a drawing element

And here's another two:

3) You can also draw your image simply to the bitmap of the picture, and
make sure the picture's bitmap itself does not change size

4) Catch the WM_ERASEBKGND message (search on Google.. many posts here
before)

Kind regards (also from Holland),

Nils Haeck
www.simdesign.nl

"R. Hoek" <*ho...@componentagro.nl> wrote in message
news:3f52ff70$1...@newsgroups.borland.com...

0 new messages