Solved

Flickerless drawing/animation

Posted on 1997-08-28
7
207 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now