Board index » delphi » Flicker when drawing to Image control

Flicker when drawing to Image control

Help!  I am writing a program that draws at run-time to the canvas of
an image box.  Every time something is drawn, the entire image box
seems to repaint itself, causing a huge flicker.  Is there anything I
can do about this?  I have tried refreshing, updating, repainting,
etc. but nothing seems to work.  Should I perhaps be using a paint box
instead of an image box? Can anybody help me?  

 

Re:Flicker when drawing to Image control


There are a few reasons why objects flicker - one is that the control is
not set to be opaque - if it were a transparent control - on refreshes
it would have to first repaint the background.  You can set a control to
opaque by setting its ControlStyle property - ie:

ControlStyle:= ControlStyle+[csOpaque];  {To avoid the flicker on
repaint}

Another trick is to capture all the WM_ERASEBACKGROUND messages for the
control and set their result to True without actually erasing the
background - this is done as follows:

interface
type
  AControl=Class(TCustomControl)
    procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message
wm_EraseBkgnd;
...

implementation

procedure TAControl.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  Message.Result:=1; {Don't erase the background}
end;

You could also do all your painting on a canvas created separately and
then assign the canvas to the control's canvas - especially important if
the paint is complex.  ie create a temporary bitmap

Quote
Mike Baker wrote:

> Help!  I am writing a program that draws at run-time to the canvas of
> an image box.  Every time something is drawn, the entire image box
> seems to repaint itself, causing a huge flicker.  Is there anything I
> can do about this?  I have tried refreshing, updating, repainting,
> etc. but nothing seems to work.  Should I perhaps be using a paint box
> instead of an image box? Can anybody help me?

--
*************************************

Ken Friesen
kfrie...@EasySoft-Law.com
Vancouver, Canada

Re:Flicker when drawing to Image control


Quote
Hans Lohninger <hlohn...@email.tuwien.ac.at> wrote:
>Mike Baker wrote:

>> Help!  I am writing a program that draws at run-time to the canvas of
>> an image box.  Every time something is drawn, the entire image box
>> seems to repaint itself, causing a huge flicker.  Is there anything I
>> can do about this?  I have tried refreshing, updating, repainting,
>> etc. but nothing seems to work.  Should I perhaps be using a paint box
>> instead of an image box? Can anybody help me?

>Mike,

>   there's quite a simple solution to it: draw on an (invisible)
>auxiliary TBitMap object and copy its contents to the image box when
>ready.

>Hope that helps,

>   Hans

I tried your solution, but the flicker problem still exists.  Copying
from one Image box to another creates flicker.  Is there something
else you're not telling me?

Mike

Re:Flicker when drawing to Image control


In article <3410a081.16958...@news.goodnet.com>,
  mba...@crystaltech.com (Mike Baker) wrote:

Quote

> Hans Lohninger <hlohn...@email.tuwien.ac.at> wrote:

> >Mike Baker wrote:

> >> Help!  I am writing a program that draws at run-time to the canvas of
> >> an image box.  Every time something is drawn, the entire image box
> >> seems to repaint itself, causing a huge flicker.  Is there anything I
> >> can do about this?  I have tried refreshing, updating, repainting,
> >> etc. but nothing seems to work.  Should I perhaps be using a paint box
> >> instead of an image box? Can anybody help me?

> >Mike,

> >   there's quite a simple solution to it: draw on an (invisible)
> >auxiliary TBitMap object and copy its contents to the image box when
> >ready.

> >Hope that helps,

> >   Hans

> I tried your solution, but the flicker problem still exists.  Copying
> from one Image box to another creates flicker.  Is there something
> else you're not telling me?

> Mike

Hey guis, look at wm_ERASEBKGND or e-mail me to give you an examplary
project, showing how to draw as many bitmaps as you want and to drag a
bitmap on a form without any flicker. btw. drawing on a second bitmap
sometimes removes the flicker, but is *awful* slow!

Greetings,
Nikolay Simeonov

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet

Other Threads