用mediaplay实现抓图

类别:Delphi 点击:0 评论:0 推荐:
关键字     

小弟前段时间曾做过保证要公开该问题的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;

 

end.

test环境win2000+dephi6.0

至于改bcb的code相信大家一目了然,我就不改那!,vc的code要的话,我过段时间公开!

还是《程序设计实践》上说的好“尽量用简单的方法解决问题".

另外小弟这段时间在写个“网吧定时炸弹”。设计主要功能是定时炸毁网吧所有机器的硬盘(定时功能是指由使用者指定发作时间)

所谓炸毁学的是泽民炸弹的做法,不过win9x,win2000,winxp都发作罢了。计划鬼门开的那天公开code,请到时候关注.

流浪的小狗没有一个家呀,没有一个家!

   

本文地址:http://com.8s8s.com/it/it5600.htm