Animated Character

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

LEEJGAsked:
Who is Participating?
 
TheNeilConnect With a Mentor Commented:
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
 
edeyCommented:
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
 
LEEJGAuthor Commented:
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
Cloud Class® Course: Amazon Web Services - Basic

Are you thinking about creating an Amazon Web Services account for your business? Not sure where to start? In this course you’ll get an overview of the history of AWS and take a tour of their user interface.

 
LEEJGAuthor Commented:
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
 
edeyCommented:
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
 
LEEJGAuthor Commented:
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
 
TheNeilCommented:
What about extracting the frames from the AVI into bitmaps and then displaying those transparently?

The Neil =:)
0
 
bogieman_Commented:
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
 
LEEJGAuthor Commented:
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
 
edeyCommented:
You can avoid this by combining the "frame" and the "background" in an offscreen bitmap first.
0
 
LEEJGAuthor Commented:
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
 
RadlerCommented:
An animated gif can be used ?

T++, Radler.
0
 
TheNeilCommented:
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
 
LEEJGAuthor Commented:
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
 
TheNeilCommented:
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
 
LEEJGAuthor Commented:
Adjusted points from 200 to 400
0
 
LEEJGAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.