如何將TAnimate的AVI文件存成多張bmp文件?(50分)

  • 主题发起人 主题发起人 leway
  • 开始时间 开始时间
L

leway

Unregistered / Unconfirmed
GUEST, unregistred user!
從Tanimate的avi文件還原出bmp文件,最好能實現無論AVI是幾色的,都能存成16色的bmp圖形。
 
nit ScreenAVIframes;

interface

uses
SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
Forms, Dialogs, MPlayer, StdCtrls, ExtCtrls, Buttons, Gauges;

type
TMainForm = class(TForm)
DisplayPanel: TPanel;
MediaPlayer: TMediaPlayer;
LabelIndex: TLabel;
ButtonSaveFrames: TButton;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
od: TOpenDialog;
procedure ButtonSaveFramesClick(Sender: TObject);
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation


{$R *.DFM}

procedure TMainForm.ButtonSaveFramesClick(Sender: TObject);
VAR
Bitmap: TBitmap;
i : INTEGER;
begin
FOR i := 1 TO MediaPlayer.Length DO
BEGIN
LabelIndex.Caption := IntToStr(i);

MediaPlayer.StartPos := i;
MediaPlayer.EndPos := i;
MediaPlayer.Play;

Bitmap := TBitmap.Create;
TRY
Bitmap.Width := DisplayPanel.Width;
Bitmap.Height := DisplayPanel.Height;
Bitmap.PixelFormat := pf24bit;

Bitmap.Canvas.CopyRect(Bitmap.Canvas.ClipRect,
MainForm.Canvas,
Rect(DisplayPanel.Left,
DisplayPanel.Top,
DisplayPanel.Left + Bitmap.Width,
DisplayPanel.Top + Bitmap.Height));
Bitmap.SaveToFile( pchar(ExtractFilePath(ParamStr(0)))+'/bbb/'+IntToStr(i) + '.BMP');
FINALLY
Bitmap.Free
END;

Sleep (250); // slow down enough to watch on fast machines
Application.ProcessMessages
END
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
od.Execute;
if od.FileName<>'' then
begin
WITH MediaPlayer
DO BEGIN
Enabled := TRUE;
Filename :=od.FileName;
Open;
TimeFormat := tfFrames;
DisplayRect := Rect(0, 0, DisplayPanel.Width, DisplayPanel.Height);
Frames := 0;
END
end;
end;

end.
 
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ComCtrls, StdCtrls, ExtCtrls, Buttons;

type
TForm1 = class(TForm)
Animate1: TAnimate;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
bmp: TBitmap;
i: integer;
begin
bmp := TBitmap.Create;
bmp.Width := Animate1.FrameWidth;
bmp.Height := Animate1.FrameHeight;

for i := 1 to Animate1.FrameCount do
begin
// Animate1.Play(i, i, 1);
Animate1.Active := false;
Animate1.StartFrame := i;
Animate1.StopFrame := i;
Animate1.Active := true;
Animate1.Update;
//sleep(1000);
BitBlt(bmp.Canvas.Handle, 0, 0, bmp.Width, bmp.Height, getdc(Animate1.Handle), 0, 0, SRCCOPY);
bmp.PixelFormat := pf4bit;
bmp.SaveToFile('c:/' + inttostr(i) + '.bmp');
end;
freeandnil(bmp);
end;

end.




object Form1: TForm1
Left = 192
Top = 107
Width = 544
Height = 375
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object Animate1: TAnimate
Left = 56
Top = 48
Width = 272
Height = 60
Active = False
CommonAVI = aviCopyFile
StopFrame = 26
end
object Button1: TButton
Left = 168
Top = 168
Width = 75
Height = 25
Caption = 'Button1'
TabOrder = 1
OnClick = Button1Click
end
end

 
后退
顶部