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

x
?
Solved

Flickerless drawing/animation

Posted on 1997-08-28
7
Medium Priority
?
218 Views
Last Modified: 2010-04-03
I have a Image control on which I'd like to do a simple horizontal wipe of a bitmap. Something like:

for i := 0 to MyBitmap.Width - 1 do begin
  BitBlt(Image1.Canvas.Handle, i, 0, 1, MyBitmap.Height,
         MyBitmap.Canvas.Handle, i, 0, SRCCOPY);
  Application.ProcessMessages;
end; {for}

Without Application.ProcessMessages nothing happens until the window is redrawn again. With Application.ProcessMessages it exhibits horrendous flicker. It seems for each step in the loop, the background is erased, and then repainted. I want to supress such erasing, and simply Blit on to the screen line by line as quick as possible. I know I could use CopyRect, but it is irrelevant, since I see the same flicker for CopyRect. Can anyone help?

P.S. I don't want to use a timer!
0
Comment
Question by:wolfcrag
  • 5
7 Comments
 
LVL 3

Author Comment

by:wolfcrag
ID: 1342854
Edited text of question
0
 
LVL 3

Author Comment

by:wolfcrag
ID: 1342855
Edited text of question
0
 
LVL 1

Expert Comment

by:miv
ID: 1342856
LockWindowUpdate(Handle of form/window);
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 3

Author Comment

by:wolfcrag
ID: 1342857
Sorry, I have to reject that answer. Maybe I didn't word my inital question properly. It's true that LockWindowUpdate stops any flickering. But it also stops the image being shown until the very end when I call LockWindowUpdate(0). I want to see each line being drawn on screen from x = 0 to x = MyBitmap.Width - 1. It might be very quick, but I should be able to see it. It's a horizontal wipe effect, in other words. LockWindowUpdate(Application.Handle) stops me from seeing it. Without it, I see the effect, but there is awful flicker.

I tried the code with the PaintBox component. It worked! So, in other words I need the image component to act like a Paintbox component for the duration of the effect. Probably there's some message I need to intercept which tells Delphi/Windows not to erase the background of the image after each call to CopyRect or BitBlt.  
0
 
LVL 1

Accepted Solution

by:
fsanchez earned 200 total points
ID: 1342858
You need to capture the EraseBackGround message for your image and control the actual erasing with one boolean variable. You can do it this way:

{ Declaration }
class TMyControl...
...
  procedure WMEraseBkgnd(var Message: TWMEraseBkgnd); message WM_ERASEBKGND;
...
  Erase: Boolean;
...
end;

{ Implementation }
procedure TMyControl.WMEraseBkgnd(var Message: TWMEraseBkgnd);
begin
  { If Erase is True  then the backgroung will be erased.
    If Erase is False then nothing happens (avoids flicker) }
  if Erase then
    inherited;
end;
...

Good luck,
Francisco Sanchez
0
 
LVL 3

Author Comment

by:wolfcrag
ID: 1342859
fsanchez,

    I'll try out your code later today. Sorry about the delay.

wolfcrag
0
 
LVL 3

Author Comment

by:wolfcrag
ID: 1342860
Thanks fsanchez, I did it!
0

Featured Post

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.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

864 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