程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> Delphi >> 用mediaplay實現抓圖

用mediaplay實現抓圖

編輯:Delphi
小弟前段時間曾做過保證要公開該問題的code(vc,bcb,dephi),剛開始小弟用拷屏的方法可抓下來總是黑呼呼的一片,後來在幾位大蝦的提示下用vc+directshow實現那該功能。

  可這樣一來,就必須用directshow來實現播放與初衷不合.從此我就鑽進那死胡同,總是想將

  directshow與activemove組件,directshow與mediaplay組件結合起來,利用IBasicVideo Interface來達到目標。可讀遍那與此相關的directsdk的頭文件,都沒有找那結合的辦法(那位大蝦實現那,請指點小弟,小弟先謝那!)。一直苦無進展,市面上有關的書都翻遍那。無用!(可見那些所謂的“高級編程技巧”都是狗屁,難度大一點的問題都回避,全是亂抄,tmd騙子),有一天小弟重讀The IBasicVideo interface supports the video propertIEs of a generic video window. Generally, this is a video renderer that draws video into a window on the display. (msdn),忽然記起在讀dephihelp是有一段相似

  TPaintBox provides a canvas that applications can use for rendering an image.(dephihelp)遂想用paintbox可能可以,try->success,code如下:

  unit Unit1;

   

  interface

   

  uses

    Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,

    Dialogs, MPlayer, ExtCtrls, StdCtrls, Menus;

   

  type

    TForm1 = class(TForm)

      MainMenu1: TMainMenu;

      filw1: TMenuItem;

      open1: TMenuItem;

      close1: TMenuItem;

      Button1: TButton;

      OpenDialog1: TOpenDialog;

      PaintBox1: TPaintBox;

      MediaPlayer1: TMediaPlayer;

      procedure FormCreate(Sender: TObject);

      procedure FormClose(Sender: TObject; var Action: TCloseAction);

      procedure PaintBox1Paint(Sender: TObject);

      procedure open1Click(Sender: TObject);

      procedure Button1Click(Sender: TObject);

    private

    imgbitmap:TBitmap;

      { Private declarations }

    public

      { Public declarations }

    end;

   

  var

    Form1: TForm1;

   

  implementation

   

  {$R *.dfm}

   

  procedure TForm1.FormCreate(Sender: TObject);

  begin

     imgbitmap:=TBitmap.Create;

     imgbitmap.Height:=200;

     imgbitmap.Width:=200;

     imgbitmap.Canvas.Rectangle(0,0,200,200);

  end;

   

  procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);

  begin

  imgbitmap.Free;

  end;

   

  procedure TForm1.PaintBox1Paint(Sender: TObject);

  begin

  PaintBox1.Canvas.CopyRect(Rect(0,0,200,200),imgbitmap.Canvas,Rect(0,0,200,200));

  end;

   

  procedure TForm1.open1Click(Sender: TObject);

  begin

  if OpenDialog1.Execute then

  begin

  MediaPlayer1.FileName:=OpenDialog1.FileName;

  MediaPlayer1.Open;

  MediaPlayer1.Display:=Form1;

  MediaPlayer1.DisplayRect:=Rect(10,10,200,200);

  end;

  end;

   

  procedure TForm1.Button1Click(Sender: TObject);

  begin

  imgbitmap.Canvas.CopyRect(Rect(0,0,200,200),form1.Canvas,Rect(10,10,200,200));

  PaintBox1.Invalidate;

  imgbitmap.SaveToFile('d:1234567.bmp');

  end;

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved