Solved

Flickerless drawing/animation

Posted on 1997-08-28
7
212 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 100 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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