//录制ACTIVEX中,供你参考,你也可以采用AVICAP 命令集
使用WIN API 的 MCI 函数集,原理是:
用mci将采集卡采来的一帧图放到剪贴板上,(你的程序上放image控件)利用
image提供的属性 把剪贴板上的图画到image上,你得放两个image,用timer控制
两个image交互显示(画好图的image显示,没画好的image不显示)。
以下是代码,供参考(别忘了给我加分哦)
--------------------------------------------------------------
unit Unit_mci;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
Menus, ExtCtrls, MPlayer, mmsystem, ComCtrls, Clipbrd, Buttons,
ExtDlgs;
type
TForm1 = class(TForm)
Panel2: TPanel;
Panel1: TPanel;
StatusBar1: TStatusBar;
Image1: TImage;
SpeedButton1: TSpeedButton;
Timer1: TTimer;
Image2: TImage;
SpeedButton2: TSpeedButton;
SpeedButton3: TSpeedButton;
SpeedButton4: TSpeedButton;
SpeedButton5: TSpeedButton;
SpeedButton6: TSpeedButton;
sp_8_24: TSpeedButton;
SavePictureDialog1: TSavePictureDialog;
SpeedButton7: TSpeedButton;
SpeedButton8: TSpeedButton;
procedure FormCreate(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure SpeedButton1Click(Sender: TObject);
procedure Timer1Timer(Sender: TObject);
procedure sp_8_24Click(Sender: TObject);
procedure SpeedButton2Click(Sender: TObject);
procedure SpeedButton5Click(Sender: TObject);
procedure SpeedButton6Click(Sender: TObject);
procedure SpeedButton4Click(Sender: TObject);
procedure SpeedButton7Click(Sender: TObject);
procedure SpeedButton8Click(Sender: TObject);
private
cat_sp_24_8:boolean;
{ Private declarations }
public
procedure mci_SendString(command_str
char);
function PlayAviWindow(x_image_1,x_image_2:Timage):boolean;
procedure VideoLoad;
{ Public declarations }
end;
var
Form1: TForm1;
{$R cat_capture.res} //引用资源文件
implementation
uses Unit_mci_source, Unit_mci_change;
{$R *.DFM}
//-----------.* * 自定义函数/过程 * *.-------------------------
// *
// * 过程:mci_SendString(command_str
char)
// * 功能:封装 API -> MciSendString(...)
//API 原形(在 mmsystem.pas 中):
//function mciSendString(lpstrCommand, lpstrReturnString: PChar;
// uReturnLength: UINT; hWndCallback: HWND): MCIERROR; stdcall;
procedure TForm1.mci_SendString(command_str
char);
var
ret : Longint;
tstr : array[0..200] of char;
begin
ret := mciSendString(command_str,nil,0,0); // ?form1
//...
end;
function TForm1.PlayAviWindow(x_image_1,x_image_2:Timage):boolean; //自定义
begin
result := false;
StatusBar1.SimpleText := '播放视频……';
//
mci_sendstring('copy cat_mci'); //300x200
if Clipboard.HasFormat(CF_BITMAP)=true then
begin
if x_image_1.Visible=false then
begin
x_image_1.Picture.Assign(Clipboard);
x_image_2.Visible := false;
x_image_1.Visible := true;
end else begin
x_image_2.Picture.Assign(Clipboard);
x_image_1.Visible := false;
x_image_2.Visible := true;
end;
mci_SendString('unfreeze cat_mci');
//
result := true;
end;
end;
procedure TForm1.VideoLoad; //加载图象时初始化图象性质
begin
mci_Sendstring('freeze cat_Mci');
mci_SendString('SetVideo cat_mci bitsperpel to 24');
mci_Sendstring('unfreeze cat_Mci');
sp_8_24.Glyph.Handle := LoadBitmap(HInstance,'A_24_8');
sp_8_24.Hint := '转换成黑白图象';
end;
//==================================================
procedure TForm1.FormCreate(Sender: TObject);
begin
speedbutton2.Enabled := false;
speedbutton3.Enabled := false;
speedbutton4.Enabled := false;
speedbutton5.Enabled := false;
speedbutton6.Enabled := false;
sp_8_24.Enabled := false;
//
cat_sp_24_8 :=false;
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
mci_SendString('close cat_mci');
end;
procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
mci_SendString('open overlay alias cat_mci');
VideoLoad;
timer1.enabled := true;
//
speedbutton2.Enabled := true;
speedbutton3.Enabled := true;
speedbutton4.Enabled := true;
speedbutton5.Enabled := true;
speedbutton6.Enabled := true;
sp_8_24.Enabled := true;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
if PlayAviWindow(image1,image2)=false then
application.MessageBox('播放视频失败。','MCI 设备',mb_ok+mb_iconStop);
end;
procedure TForm1.sp_8_24Click(Sender: TObject); // -- ok --
begin
mci_SendString('freeze cat_mci');
if cat_sp_24_8=false then
begin
mci_SendString('SetVideo cat_mci bitsperpel to 8');
sp_8_24.Glyph.Handle := LoadBitmap(HInstance,'A_8_24');
cat_sp_24_8 := true;
sp_8_24.Hint := '转换成彩色图象';
end else begin
mci_SendString('SetVideo cat_mci bitsperpel to 24');
sp_8_24.Glyph.Handle := LoadBitmap(HInstance,'A_24_8');
cat_sp_24_8 := false;
sp_8_24.Hint := '转换成黑白图象';
end;
mci_SendString('unfreeze cat_mci');
end;
procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
savePictureDialog1.Filter := '*.BMP|*.bmp+*.JPG|*.jpg';
savePictureDialog1.DefaultExt := 'BMP';
if SavePictureDialog1.Execute=true then
if image1.Visible=true then
image1.Picture.SaveToFile(SavePictureDialog1.filename)//'aa.bmp')
else
image2.Picture.SaveToFile(SavePictureDialog1.filename);//'aa.bmp');
end;
procedure TForm1.SpeedButton5Click(Sender: TObject);
var
aa1:string;
aa2:array[0..127] of char;
reg01:TRegistry;
begin
form_change.Caption := '调节亮度和饱和度';
//
if form_change.ShowModal=mrok then
begin
mci_sendstring('freeze cat_mci');
//
aa1 := strpas('setvideo cat_mci brightness to ');
aa1 := aa1+form_change.Edit1.text;
strpcopy(aa2,aa1);
mci_SendString(aa2);
//
aa1 := strpas('setvideo cat_mci color to ');
aa1 := aa1+form_change.Edit2.text;
strpcopy(aa2,aa1);
mci_SendString(aa2);
//
mci_Sendstring('unfreeze cat_mci');
end;
end;
procedure TForm1.SpeedButton6Click(Sender: TObject);
var
aa1:string;
aa2:array[0..127] of char;
reg02:Tregistry;
begin
form_change.Caption := '调节对比度和色调值';
//
if form_change.ShowModal=mrok then
begin
mci_Sendstring('freeze cat_mci');
//
aa1 := strpas('setvideo cat_mci contrast to ');
aa1 := aa1+form_change.Edit1.text;
strpcopy(aa2,aa1);
mci_SendString(aa2);
//
aa1 := strpas('setvideo cat_mci tint to ');
aa1 := aa1+form_change.Edit2.text;
strpcopy(aa2,aa1);
mci_SendString(aa2);
//
mci_Sendstring('unfreeze cat_mci');
end;
end;
procedure TForm1.SpeedButton4Click(Sender: TObject);
var
aa1:string;
aa2:array[0..127] of char;
begin
if form_source.ShowModal=mrok then
begin
mci_Sendstring('freeze cat_mci');
//
aa1 := strpas('setvideo cat_mci number ')+form_source.aa;
strpcopy(aa2,aa1);
mci_Sendstring(aa2);
//
mci_Sendstring('unfreeze cat_mci');
end;
end;
end.