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

Repainting the canvas faster ?

1,021 views
Skip to first unread message

Josep Maria Gómez Boada

unread,
Feb 20, 2001, 5:20:40 AM2/20/01
to
Hi all,

I'm doing a component that is like an "electocardiogram", painting at
canvas.
My problem is i must refresh the "health line" every 100 milliseconds, and
the repainting is slowly, and the canvas is fliking. (because i put te
canvas white, i draw the grid lines and repaint the "health line" with a new
value)
The problem growns when the canvas growns.

Any suggestion ?

thanks,

Joseph Maria Gomez


Ivo Bauer

unread,
Feb 20, 2001, 7:24:22 AM2/20/01
to

"Josep Maria Gómez Boada" wrote:

> the repainting is slowly, and the canvas is fliking.

Hi.

If your control is TCustomControl (TWinControl) descendant, you should set its
DoubleBuffer property to True to eliminate flicker.

If your control descends from TGraphicControl then you have to write a
double-buffering mechanism by yourself. In the overriden Paint method create a
bitmap and set its dimensions according to your control dimensions
(GetClientRect). Then redirect all drawing operations into TBitmap.Canvas, and
when you're done, copy the bitmap's canvas content into your control's canvas (I
am using Win API BitBlt function directly in these cases or you can use some
methods contained in TCanvas class).

Hope this helps. Ivo.


Josep Maria Gómez Boada

unread,
Feb 20, 2001, 11:12:18 AM2/20/01
to
thanks Ivo,

Is a TCustomControl and I set doublebuffered to True and seems to do the
same...

The problem is every time i need repaint the "Health line", i must repaint
the background, repaint the grid and
repaint the "health line" with a new value added to simulate the "paper"
movement.

thanks again,

Josep Maria Gomez Boada

Ivo Bauer <Ivo....@upce.cz> escribió en el mensaje de noticias
3A9261F6...@upce.cz...


>
>
> "Josep Maria Gómez Boada" wrote:
>
> > the repainting is slowly, and the canvas is fliking.
>
> Hi.
>
> If your control is TCustomControl (TWinControl) descendant, you should set
its
> DoubleBuffer property to True to eliminate flicker.
>
> If your control descends from TGraphicControl then you have to write a
> double-buffering mechanism by yourself. In the overriden Paint method
create a

> Hope this helps. Ivo.
>
>


William Meyer

unread,
Feb 20, 2001, 12:53:33 PM2/20/01
to
"Josep Maria Gómez Boada" <josepma...@teleline.es> wrote in message
news:3a92975d_2@dnews...

>
> The problem is every time i need repaint the "Health line", i must repaint
> the background, repaint the grid and
> repaint the "health line" with a new value added to simulate the "paper"
> movement.
Have you looked for ready-made components? I think you will find something
like what you are looking for on www.torry.net. Perhaps if you try one of
these, it may not have the problem. If so, you can either use it, or if the
source is available, you may be able to learn from it how to solve your
problem. Also, there are commercial components at www.swiftsoft.de which may
provide the function you seek, and those use all sorts of tricks to manage
performance.

HTH,

Bill


Peter Below (TeamB)

unread,
Feb 20, 2001, 3:33:01 PM2/20/01
to
In article <3a9244f4_1@dnews>, Josep Maria Gómez Boada wrote:
> I'm doing a component that is like an "electocardiogram", painting at
> canvas.

What kind of canvas are you using? An images canvas, a paintbox, something
else? The solution to the flicker problem is to paint the complete image to a
background bitmap first and then copy that to the foreground canvas in one
operation. I also suggest to use the PolyLine canvas function to draw your
curve, it is much faster than drawing each line segment with lineto/moveto, or
(Horror!) to set pixels one by one.

Peter Below (TeamB) 10011...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Uwe Wolfgang Radu

unread,
Feb 20, 2001, 4:21:04 PM2/20/01
to
Sometimes it can be useful to store the background (e.g. the "paper") as a
bitmap, especially if it is really busy. Each time the paper moves, you
simply copy the bitmap again into the off-screen buffer, offset by the
correct number of pixels so it appears to move. This gives you a blank
drawing surface for the next "frame". Of couse, the bitmap needs to be one
repeating segment larger than the actual display, and you keep shifting it
until you've moved it an entire segment, then you start all over again. This
works well with repeating patterns such as graph paper, and gives you the
option of having a really fancy background texture at no extra cost.
Depending on you graphics card doing a bitblt such as copying a bitmap can
actually be faster than drawing a bunch of lines and text, up to a certain
display size.

--
Uwe W. Radu


Robert Cerny

unread,
Feb 20, 2001, 4:49:53 PM2/20/01
to
Well, such a thing requires full paint only the first time, after that you
update only a thin delta.
So, instead of invalidating whole window, use ScrollWindow function and in
WM_Paint handler ask for invalid area (GetUpdateRect) to paint only that.
Also, if you paint the background too, create the WM_EraseBkgnd handler and
return 1.
It will run MUCH faster and you won't see any flicker.

--
Robert

Josep Maria Gómez Boada wrote in message <3a9244f4_1@dnews>...

Ivo Bauer

unread,
Feb 21, 2001, 2:55:24 AM2/21/01
to

"Josep Maria Gómez Boada" wrote:

> Is a TCustomControl and I set doublebuffered to True and seems to do the
> same...

If your control is TCustomControl descendant, setting its DoubleBuffer property
to true should have the same effects as I described in my first comment, thus
eliminating flicker. If you want to improve drawing performance (since you need
to redraw the control in a very short periods of time), you can:

1) start thinking about usign pre-rendered paper background with grid (see
comment from Uwe in this queue) and when painting control image (in Paint
method) only copy corresponding block from background paper bitmap to control
canvas instead of direct rendering each time it is needed.

2) When you don't need to redraw entire control during periodical updates,
bypass the Paint method and draw only a portion of the control that needs to
update directly into canvas.

Good luck, Ivo.


Josep Maria Gómez Boada

unread,
Feb 22, 2001, 4:41:32 AM2/22/01
to
Hi Peter,

Peter Below (TeamB) <10011...@compuXXserve.com> escribió en el mensaje de
noticias VA.000069d...@antispam.compuserve.com...


> In article <3a9244f4_1@dnews>, Josep Maria Gómez Boada wrote:
> > I'm doing a component that is like an "electocardiogram", painting at
> > canvas.
>
> What kind of canvas are you using? An images canvas, a paintbox, something

Is the CustomControl's canvas property.

> else? The solution to the flicker problem is to paint the complete image
to a
> background bitmap first and then copy that to the foreground canvas in one

I'll tryit.

> operation. I also suggest to use the PolyLine canvas function to draw your
> curve, it is much faster than drawing each line segment with
lineto/moveto, or

I was tryit but the result was the same.

thanks


Josep Maria Gómez Boada

unread,
Feb 22, 2001, 4:45:25 AM2/22/01
to
Hi Bill,

> Have you looked for ready-made components? I think you will find something

Yes but i can't find nothing similar i need and i prefer to do my self
component.

> problem. Also, there are commercial components at www.swiftsoft.de which
may
> provide the function you seek, and those use all sorts of tricks to manage
> performance.
>
> HTH,

thanks at all.

Josep Maria


0 new messages