188 lines
4.5 KiB
Plaintext
188 lines
4.5 KiB
Plaintext
unit umain;
|
|
|
|
interface
|
|
|
|
uses
|
|
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
|
StdCtrls, ieview, imageenview, Buttons, ieds, ComCtrls, ExtCtrls, Menus, hyieutils, imageenproc, iexBitmaps, hyiedefs, iesettings,
|
|
iexLayers, iexRulers;
|
|
|
|
type
|
|
Tfmain = class(TForm)
|
|
ImageEnView1: TImageEnView;
|
|
Panel1: TPanel;
|
|
GroupBox1: TGroupBox;
|
|
Label1: TLabel;
|
|
SpeedButton1: TSpeedButton;
|
|
ComboBox1: TComboBox;
|
|
Label4: TLabel;
|
|
ListBox1: TListBox;
|
|
Label5: TLabel;
|
|
Label6: TLabel;
|
|
Label7: TLabel;
|
|
Edit1: TEdit;
|
|
Edit2: TEdit;
|
|
Label8: TLabel;
|
|
ComboBox2: TComboBox;
|
|
Label2: TLabel;
|
|
edtFilename: TEdit;
|
|
procedure FormActivate(Sender: TObject);
|
|
procedure ImageEnView1DShowNewFrame(Sender: TObject);
|
|
procedure SpeedButton1Click(Sender: TObject);
|
|
procedure ComboBox1Change(Sender: TObject);
|
|
procedure ComboBox2Change(Sender: TObject);
|
|
private
|
|
{ Private declarations }
|
|
public
|
|
{ Public declarations }
|
|
procedure Connect;
|
|
procedure Disconnect;
|
|
procedure ShowVideoFormats;
|
|
end;
|
|
|
|
var
|
|
fmain: Tfmain;
|
|
|
|
implementation
|
|
|
|
{$R *.DFM}
|
|
{$R WindowsTheme.res}
|
|
|
|
procedure Tfmain.FormActivate(Sender: TObject);
|
|
begin
|
|
// add a new layer with image 1.png
|
|
ImageEnView1.LayersAdd('1.png', 40, 40);
|
|
// Fill video source combobox
|
|
ComboBox1.Items.Assign(ImageEnView1.IO.DShowParams.VideoInputs);
|
|
// Select first item
|
|
ComboBox1.ItemIndex := 0;
|
|
//
|
|
ShowVideoFormats;
|
|
end;
|
|
|
|
procedure Tfmain.Connect;
|
|
var
|
|
w, h: integer;
|
|
begin
|
|
if (not ImageEnView1.IO.DShowParams.Connected) then
|
|
begin
|
|
// set video source as index of IO.DShowParams.VideoInputs
|
|
w := 0; h := 0;
|
|
if ListBox1.ItemIndex > -1 then
|
|
begin
|
|
w := ImageEnView1.IO.DShowParams.VideoFormats[ ListBox1.ItemIndex ].MaxWidth;
|
|
h := ImageEnView1.IO.DShowParams.VideoFormats[ ListBox1.ItemIndex ].MaxHeight;
|
|
end;
|
|
ImageEnView1.IO.DShowParams.SetVideoInput(ComboBox1.ItemIndex,
|
|
0, // set this parameter if you have more than one camera with same name
|
|
w, // capture width
|
|
h, // capture height
|
|
'' // format
|
|
);
|
|
// enable frame grabbing
|
|
ImageEnView1.IO.DShowParams.EnableSampleGrabber := true;
|
|
// connect to the video input
|
|
ImageEnView1.IO.DShowParams.Connect;
|
|
end;
|
|
end;
|
|
|
|
procedure Tfmain.Disconnect;
|
|
begin
|
|
// stop and disconnect
|
|
ImageEnView1.IO.DShowParams.Disconnect;
|
|
end;
|
|
|
|
// Capture button
|
|
procedure Tfmain.SpeedButton1Click(Sender: TObject);
|
|
var
|
|
w, h: integer;
|
|
f: AnsiString;
|
|
begin
|
|
if SpeedButton1.Down then
|
|
begin
|
|
imageenview1.IO.CreateAVIFile(edtFilename.Text, 10, 'msvc');
|
|
//
|
|
Connect;
|
|
// show info
|
|
ImageEnView1.IO.DShowParams.GetCurrentVideoFormat(w, h, f);
|
|
Label4.Caption := 'Capturing at ' + inttostr(w) + 'x' + inttostr(h) + ' ' + f;
|
|
// start capture
|
|
ImageEnView1.IO.DShowParams.Run;
|
|
end
|
|
else
|
|
begin
|
|
Disconnect;
|
|
imageenview1.io.CloseAVIFile;
|
|
end;
|
|
end;
|
|
|
|
procedure Tfmain.ShowVideoFormats;
|
|
var
|
|
i: integer;
|
|
s: string;
|
|
begin
|
|
Connect;
|
|
|
|
// fills video formats list box
|
|
ListBox1.Clear;
|
|
with ImageEnView1.IO.DShowParams do
|
|
for i := 0 to VideoFormatsCount - 1 do
|
|
begin
|
|
with VideoFormats[i] do
|
|
s := SysUtils.Format('%s %dx%d', [Format, MaxWidth, MaxHeight]);
|
|
ListBox1.Items.Add(s);
|
|
end;
|
|
ListBox1.ItemIndex:=0;
|
|
|
|
// fills video source inputs
|
|
ComboBox2.Items.Assign(ImageEnView1.IO.DShowParams.VideoInputSources);
|
|
// set current video source input
|
|
ComboBox2.ItemIndex := ImageEnView1.IO.DShowParams.VideoInputSource;
|
|
|
|
Disconnect;
|
|
end;
|
|
|
|
// changes video source
|
|
|
|
procedure Tfmain.ComboBox1Change(Sender: TObject);
|
|
begin
|
|
ShowVideoFormats;
|
|
end;
|
|
|
|
// set video source input
|
|
|
|
procedure Tfmain.ComboBox2Change(Sender: TObject);
|
|
begin
|
|
ImageEnView1.IO.DShowParams.VideoInputSource := ComboBox2.ItemIndex;
|
|
end;
|
|
|
|
// We have got a new frame
|
|
|
|
procedure Tfmain.ImageEnView1DShowNewFrame(Sender: TObject);
|
|
var
|
|
ss: string;
|
|
begin
|
|
ImageEnView1.LayersCurrent:=0;
|
|
ImageEnView1.IO.DShowParams.GetSample(ImageEnView1.IEBitmap);
|
|
|
|
// display datatime
|
|
ss := FormatDateTime('c', date + time);
|
|
with ImageEnView1.IEBitmap.Canvas do
|
|
begin
|
|
Brush.Style := bsClear;
|
|
Font.Color := clWhite;
|
|
TextOut(0, 0, ss);
|
|
end;
|
|
|
|
// uncomment if you want merge image also in the saved AVI
|
|
//ImageEnView1.LayersMerge(0,1,false);
|
|
|
|
ImageEnView1.IO.SaveToAVI;
|
|
|
|
ImageEnView1.Update;
|
|
|
|
ImageEnView1.Paint;
|
|
end;
|
|
|
|
end.
|