BorderRemove example for Delphi
// add this to Form Private Section.
private
{ Private declarations }
{….}
hRgnAll : HRGN;
procedure TForm1.Button1Click(Sender: TObject);
var
nRet : Integer;
begin
{Border Remove}
{This example updates a region with the borders of a bitmap}
{For the example, windows regions are passed to the OnBorderRemove Event and combined.}
{In practice it would be easier and faster to just update a LEAD region representing the changes}
{The border is removed from the image}
{Create a NULL region}
hRgnAll := CreateRectRgn(0, 0, 0, 0);
nRet := LEADImage1.BorderRemove(BORDER_CALLBACK_REGION or BORDER_USE_VARIANCE, BORDER_TOP or BORDER_BOTTOM or BORDER_LEFT or BORDER_RIGHT, 20, 2, 5);
if (nRet = SUCCESS) then
begin
LEADImage1.FreeRgn ();
LEADImage1.SetRgnHandle (hRgnAll, 0, 0, L_RGN_SET);
LEADImage1.RgnFrameType := ftAnimated;
end;
{delete the Windows Rgn}
DeleteObject(hRgnAll);
end;
procedure TForm1.LEADImage1BorderRemove (Sender: TObject; hBorderRgn: L_HRGN;
uBorderToRemove, nBoundingRectLeft, nBoundingRectTop, nBoundingRectWidth,
nBoundingRectHeight: Integer);
var
sBorder : String;
crOut : String;
szTemp: array[0..255] of Char;
begin
CombineRgn(hRgnAll, hRgnAll, hBorderRgn, RGN_OR);
case uBorderToRemove of
BORDER_TOP:
sBorder := 'Top';
BORDER_LEFT:
sBorder := 'Left';
BORDER_RIGHT:
sBorder := 'Right';
BORDER_BOTTOM:
sBorder := 'Bottom';
end;
crOut := Format('Border - %s Bounds:%d,%d,%d,%d',
[sBorder,
nBoundingRectLeft,
nBoundingRectTop,
nBoundingRectWidth,
nBoundingRectHeight]);
OutputDebugString(StrPCopy(szTemp,crOut));
LEADImage1.DocCleanSuccess := SUCCESS_REMOVE;
end;