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
Solved

Animated Character

Posted on 2000-05-08
17
269 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
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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
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…

856 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