zw版【转发·*nvp系列Delphi例程】HALCON DirectShow (Delphi Prism)
namespace DirectShow_Prism;
interface
uses
System.Drawing,
System.Collections,
System.Collections.Generic,
System.Windows.Forms,
System.ComponentModel,
HalconDotNet;
type
/// <summary>
/// Summary description for MainForm.
/// </summary>
MainForm = partial class(System.Windows.Forms.Form)
private
method MainForm_Load(sender: System.Object; e: System.EventArgs);
method MainForm_FormClosing(sender: System.Object; e: System.Windows.Forms.FormClosingEventArgs);
method timer1_Tick(sender: System.Object; e: System.EventArgs);
method button1_Click(sender: System.Object; e: System.EventArgs);
private
var fg: HFramegrabber := new HFramegrabber();
var img: HImage;
var mtype: String := '';
var w: System.Int32;
h: System.Int32;
protected
method Dispose(disposing: Boolean); override;
public
constructor;
end;
implementation
{$REGION Construction and Disposition}
constructor MainForm;
begin
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
end;
method MainForm.Dispose(disposing: Boolean);
begin
if disposing then begin
if assigned(components) then
components.Dispose();
//
// TODO: Add custom disposition code here
//
end;
inherited Dispose(disposing);
end;
{$ENDREGION}
method MainForm.MainForm_Load(sender: System.Object; e: System.EventArgs);
begin
fg.OpenFramegrabber(new HTuple('DirectShow'), new HTuple(1), new HTuple(1), new HTuple(0), new HTuple(0), new HTuple(0), new HTuple(0), new HTuple('default'), new HTuple(8), new HTuple('rgb'), new HTuple(-1), new HTuple('false'), new HTuple('default'), new HTuple('[1] ASUS USB2.0 Webcam'), new HTuple(0), new HTuple(-1))
end;
method MainForm.button1_Click(sender: System.Object; e: System.EventArgs);
begin
if button1.Text = 'Grab Start' then begin
button1.Text := 'Grab Stop';
timer1.Enabled := true
end
else begin
timer1.Enabled := false;
button1.Text := 'Grab Start'
end
end;
method MainForm.timer1_Tick(sender: System.Object; e: System.EventArgs);
begin
img := fg.GrabImage();
img.GetImagePointer1(out mtype, out w, out h);
hWindowControl1.HalconWindow.SetPart(0, 0, h - 1, w - 1);
hWindowControl1.HalconWindow.DispObj(img);
HOperatorSet.ClearObj(img);
//img.Dispose();
end;
method MainForm.MainForm_FormClosing(sender: System.Object; e: System.Windows.Forms.FormClosingEventArgs);
begin
timer1.Enabled := false;
fg.Dispose()
end;
end.