zw版【转发·台湾nvp系列Delphi例程】HALCON SetWindowExtent
zw版【转发·台湾nvp系列Delphi例程】HALCON SetWindowExtent
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, OleCtrls, HALCONXLib_TLB, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
HWindowXCtrl1: THWindowXCtrl;
Button2: TButton;
procedure FormShow(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
win : HWindowX;
img : HImageX;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.FormShow(Sender: TObject);
begin
win := HWindowXCtrl1.HalconWindow;
img := CoHImageX.Create;
img.ReadImage('ic1');
end;
procedure TForm1.Button1Click(Sender: TObject);
var
w, h : OleVariant;
c, w0, h0 : Integer;
dr, dc : Integer;
begin
w := img.GetImageSize(h);
win.GetWindowExtents(c, w0, h0);
dr := (Integer(h) - h0) div 2;
dc := (Integer(w) - w0) div 2;
win.ClearWindow;
win.SetPart(dr, dc, h0 + dr, w0 + dc);
img.DispObj(win);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
w, h : OleVariant;
begin
w := img.GetImageSize(h);
win.SetWindowExtents(0, 0, HWindowXCtrl1.HWidthPixels, HWindowXCtrl1.HHeightPixels);
win.ClearWindow;
win.SetPart(0, 0, h - 1, w - 1);
img.DispObj(win);
end;
end.