ImageEn, unit imageenview |
|
TImageEnView.LayersCreateFromEdge
Declaration
function LayersCreateFromEdge(x, y: integer; Tolerance: integer; MaxFilter: boolean = False; idx: Integer = -1): Integer;
Description
Creates a new
Polyline layer with a closed polyline (polygon) along the edge of the background layer.
The edge is determined by simulating a flood fill starting at the point specified by x,y (which are bitmap or client area points depending on
SelectionBase).
Tolerance specifies the color difference between the starting pixel and the pixel being tested (Range: 0 - 255).
Set
MaxFilter to True to apply a maximum filter that removes noise.
idx specifies the insertion index for the layer, or -1 to append.
Result is the index of the created layer, or -1 if the method fails
Note: If
SelectionBase = iesbClientArea then x and y are assumed to be visible points on the control. If iesbBitmap, the points specify a position on the bitmap.
| Demos\LayerEditing\MagicFillToPolygon\Magic2Polygon.dpr |
| Demos\ImageEditing\EveryMethod\EveryMethod.dpr |
Method Testing
ImageEnView1.IO.LoadFromFile( 'D:\TestImage.jpg' );
// Automatically select a color region and convert it to a polygon
ImageEnView1.SelectionBase := iesbBitmap;
if ImageEnView1.LayersCreateFromEdge( ClickPt.X, ClickPt.Y, 54, False ) > 0 then
begin
ImageEnView1.CurrentLayer.BorderWidth := 2;
ImageEnView1.CurrentLayer.BorderColor := Color;
ImageEnView1.CurrentLayer.FillColor := clWhite;
ImageEnView1.LayersMergeAll();
end;
// Create a new polygon layer when the user clicks on the image
procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
begin
ImageEnView1.SelectionBase := iesbClientArea;
ImageEnView1.LayersCreateFromEdge( X, Y, 25, true );
TIEPolyLineLayer( ImageEnView1.CurrentLayer ).LineColor := clBlack;
TIEPolyLineLayer( ImageEnView1.CurrentLayer ).FillColor := clNone;
ImageEnView1.Update();
end;
// Create a new polygon using a floodfill from the top left of the background image
ImageEnView1.SelectionBase := iesbClientArea;
ImageEnView1.LayersCreateFromEdge( ImageEnView1.XBmp2Scr( 0 ), ImageEnView1.YBmp2Scr( 0 ), 25, true);
TIEPolyLineLayer( ImageEnView1.CurrentLayer ).LineColor := clRed;
TIEPolyLineLayer( ImageEnView1.CurrentLayer ).LineWidth := 2;
TIEPolyLineLayer( ImageEnView1.CurrentLayer ).FillColor := clWhite;
TIEPolyLineLayer( ImageEnView1.CurrentLayer ).Transparency := 128; // 50% transparent
ImageEnView1.Update();
See Also
◼SmoothJaggedEdges◼SimplifyPolygon◼SimplifyPolygon2◼LayersCreatePolylineFromSelection