主页 > 编程资料 > Delphi >
发布时间:2015-09-22 作者:网络 阅读:152次

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;

关键字词: