Solved

Flickerless drawing/animation

Posted on 1997-08-28
7
208 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

816 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