Solved

Flickerless drawing/animation

Posted on 1997-08-28
7
206 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Firewall issues 6 85
How to use TArray to combine methods for different arrays? 12 87
Delphi XE10 Round Image 2 56
find a node in VST 2 47
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

13 Experts available now in Live!

Get 1:1 Help Now