RSS订阅 | 匿名投稿
您的位置:网站首页 > 媒体 > 正文

delphi中如何捕获MediaPlayer播放的视频中的每一帧 ?

作者:admin 来源:未知 日期:2010/11/11 21:32:59 人气: 标签:

procedure TForm1.Button1Click(Sender: TObject);
var
Bitmap : TBitmap;
ImageRect : TRect;
ImageWidth : Integer;
ImageHeight : Integer;
Position : Integer;
i : Integer;
begin
if OpenDialog1.Execute then
begin
MediaPlayer1.FileName := OpenDialog1.FileName;
MediaPlayer1.Display := Form2;
MediaPlayer1.Open;

ImageRect := MediaPlayer1.DisplayRect;
ImageWidth := ImageRect.Right - ImageRect.Left + 1;
ImageHeight := ImageRect.Bottom - ImageRect.Top + 1;

Form2.FormStyle := fsStayOnTop;
Form2.ClientWidth := ImageWidth;
Form2.ClientHeight := ImageHeight;

MediaPlayer1.AutoRewind := False;
MediaPlayer1.Play;
MediaPlayer1.Position := 0;
MediaPlayer1.Frames := 1;

Bitmap := TBitmap.Create;
try
Bitmap.Width := ImageWidth;
Bitmap.Height := ImageHeight;

i := 0;
repeat
Position := MediaPlayer1.Position;
Bitmap.Canvas.CopyRect( ImageRect,Form2.Canvas, ImageRect);
Bitmap.SaveToFile( '.\' + IntToStr(i) + '.bmp');
MediaPlayer1.Step;
inc(i);
until MediaPlayer1.Position = Position;

finally
FreeAndNil(Bitmap);
end;

end;

end;

读完这篇文章后,您心情如何?
0
0
0
0
0
0
0
0
本文网址: