delphi编程捕获MediaPlayer播放的视频中的每一帧

减小字体 增大字体 作者:佚名  来源:转载  发布时间:2010-11-11 22:17:21

本文主要讲解的在Delphi里如何捕获视频的每一帧的方法,参考如下代码:

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;

本文来源:http://www.delphitop.com/html/meiti/1502.html

Tags:

作者:佚名
  • 好的评价 如果您觉得此文章好,就请您
      0%(0)
  • 差的评价 如果您觉得此文章差,就请您
      0%(0)

文章评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分) 查看完整评论