Solved

Animated Character

Posted on 2000-05-08
17
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 4
  • 3
  • +2
17 Comments
 
LVL 6

Expert Comment

by:edey
ID: 2789272
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
ID: 2789377
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
ID: 2789393
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
Independent Software Vendors: 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 6

Expert Comment

by:edey
ID: 2789483
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
ID: 2789894
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
ID: 2791509
What about extracting the frames from the AVI into bitmaps and then displaying those transparently?

The Neil =:)
0
 
LVL 1

Expert Comment

by:bogieman_
ID: 2792289
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
ID: 2794148
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
 
LVL 6

Expert Comment

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

Author Comment

by:LEEJG
ID: 2794753
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
ID: 2801668
An animated gif can be used ?

T++, Radler.
0
 
LVL 5

Expert Comment

by:TheNeil
ID: 2803529
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
ID: 2803754
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
ID: 2803848
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
ID: 2804715
Adjusted points from 200 to 400
0
 

Author Comment

by:LEEJG
ID: 2804716
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
ID: 2804816
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

Industry Leaders: 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!

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…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

739 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