Solved

Animated Character

Posted on 2000-05-08
17
265 Views
Last Modified: 2013-12-03
Hi There,

I am looking for a bit of advice. I am trying to create an animated character which will be displayed on the screen. It needs to be always on top and the source must come from a avi file.

Whats the best way to do this??

Many Thanks

0
Comment
Question by:LEEJG
  • 8
  • 4
  • 3
  • +2
17 Comments
 
LVL 6

Expert Comment

by:edey
Comment Utility
well you could put a TMediaPlayer on a form, make the form topmost, and make sure to call pplication.restoreTopMosts in the form's onDeactivate handler.


GL
Mike
0
 

Author Comment

by:LEEJG
Comment Utility
The only problem is that i want the charater to walk in from the left side of the screen above the start bar as if he was "Walking on the screen". i.e no background to the form.

Sorry i did'nt explain this very well. :-)
0
 

Author Comment

by:LEEJG
Comment Utility
The only problem is that i want the charater to walk in from the left side of the screen above the start bar as if he was "Walking on the screen". i.e no background to the form.

Sorry i did'nt explain this very well. :-)
0
 
LVL 6

Expert Comment

by:edey
Comment Utility
hmmm.... this is more complicated.
because there is no really good way to create a transparent window you have to resort to either:
1)"highjacking" the computer, so the "background" doesn't change, ie. the user watches a movie that only looks like it's pasted on top of thier desktop.
2)draw directly to the desktop, putting in all kinds of effort to ensure that the desktop is cleaned up, in all the right places, in real time.

Perhaps a little more info on the project would help.


Gl
mike
0
 

Author Comment

by:LEEJG
Comment Utility
Hi mike,

What i am trying to do is the same as the programs that can be downloaded from http://stuart.messagemates.com/index.html But i need to get the animation from an avi file and keep it on top at all times.

Many Thanks
Lee
0
 
LVL 5

Expert Comment

by:TheNeil
Comment Utility
What about extracting the frames from the AVI into bitmaps and then displaying those transparently?

The Neil =:)
0
 
LVL 1

Expert Comment

by:bogieman_
Comment Utility
If you want to draw directly on the desktop:

var
DesktopCanvas:TCanvas
begin
DesktopCanvas:=TCanvas.create;
try
DesktopCanvas.handle:=Getdc(0);
DesktopCanvas.draw(0,0,yourimage);
finally
DesktopCanvas.free;
end;
end;

You will have to draw each frame one after another, using a timer or a thread - but as edey says, you will need to "clean" up the canvas - you can use InvalidateRect(...) to refresh certain areas.
0
 

Author Comment

by:LEEJG
Comment Utility
I Have extracted the images as TheNiel said and tried displaying the transparently with a TImage the only problem is that i get a horrible black flicker when it draws the image. Is there any way to stop this or can i do it using the bogiemans way??
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 6

Expert Comment

by:edey
Comment Utility
You can avoid this by combining the "frame" and the "background" in an offscreen bitmap first.
0
 

Author Comment

by:LEEJG
Comment Utility
Hi edey, i have just tried combining the frame and the background in an offscreen bitmap, but when i try and copy this to the forms canvas it then flickers first.

I must be doing something wrong!

Could you please post me some sample code for doing this ??

Many thanks
Lee.
0
 
LVL 4

Expert Comment

by:Radler
Comment Utility
An animated gif can be used ?

T++, Radler.
0
 
LVL 5

Expert Comment

by:TheNeil
Comment Utility
If you do it my way (extracting the frames then displaying them transparently) then you'll need to capture the section of the desktop that you're interested THEN draw the frame transparently onto that THEN put the TImage onto the screen

The Neil =:)
0
 

Author Comment

by:LEEJG
Comment Utility
Hi The Neil,

Thats exactly what i want.

If you have some code to do this could you please post or email it to me and i will double the points to 400 for you

Thanks
Lee

email : lee@lgnet.demon.co.uk
0
 
LVL 5

Expert Comment

by:TheNeil
Comment Utility
Capturing the desktop is easy so what I'd do is (in algorithm form):

Capture the entire desktop
Extract the section that you want your animation to work in
Repeatedly draw the animation transparently onto this stripp

In code it would be:

PROCEDURE TForm1.GetDesktopStrip(bmpImage : TBitmap);
VAR
  WndDC     : HDc;
  WndRect   : TRect;
  WndCanvas : TCanvas;
  Wnd       : HWND;
  Wwidth    : INTEGER;
  Wheight   : INTEGER;
  bmpTemp   : TBitmap;
BEGIN
  Image1.AutoSize := FALSE; // important!!!
  Wnd := GetDesktopWindow;
  WndDC := GetWindowDC(Wnd);
  WndCanvas := TCanvas.Create;
  WndCanvas.Handle := WndDC;
  GetWindowRect(Wnd, WndRect);

  WWidth  := WndRect.Right - WndRect.Left;
  WHeight := WndRect.Bottom - WndRect.Top;

  bmpTemp := TBitmap.Create;
  bmpTemp.Width := WWidth;
  bmpTemp.Height := WHeight;
  bmpTemp.Canvas.CopyRect(Rect(0, 0, WWidth, WHeight), WndCanvas, Rect(0, 0, WWidth, WHeight));
  WndCanvas.Free;
  ReleaseDC(Wnd, WndDC);

  bmpImage.Width := <Animation width>;
  bmpImage.Height := <Animation Height>;
  bmpImage.Canvas.Draw(-Left, -Top, bmpTemp);

  bmpTemp.Free;
END;

This isn't everything as you'll have to create a borderless form with a TImage on it, position it where you want it, and then draw your character on top of it, but this will (or should) get you the section of desktop to use as a backdrop for your anim. If you need code for drawing the character on top of your backdrop then try this:

PROCEDURE TForm1.DrawFrame(bmpStrip, bmpChar, bmpOutput : TBitmap; iX, iY : LONGINT);
BEGIN
  bmpChar.Transparent := TRUE;
  bmpOutput.Canvas.Draw(0, 0, bmpStrip);
  bmpOutput.Canvas.Draw(iX, iY, bmpChar);
END;

Then just output bmpOutput to your TImage component and off you go (Make sure that bmpOutput is the same size as bmpStrip before you call the DrawFrame routine though)

If you need anything else then just ask

The Neil =:)
0
 

Author Comment

by:LEEJG
Comment Utility
Adjusted points from 200 to 400
0
 

Author Comment

by:LEEJG
Comment Utility
Hi The Neil,

Thanks for the code, works brilliant.

one last thing, when i use AviStreamGetFrame the winapi help says it "Returns a pointer to the frame data if successful or NULL otherwise. The frame data is returned as a packed DIB."

How can i convert this to a TBitmap

Thanks
Lee.
0
 
LVL 5

Accepted Solution

by:
TheNeil earned 400 total points
Comment Utility
Err I don't know. Have you tried assigning the data into a TBitmap?

Why are you trying to get the frame data back?

The Neil =:(
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

762 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

15 Experts available now in Live!

Get 1:1 Help Now