ImageEn, unit imageenview




function LayersCreateFromEdge(x, y: integer; Tolerance: integer; MaxFilter: boolean = False; idx: Integer = -1): Integer;


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.
Tolerance specifies the color difference between the starting pixel and the pixel being tested.
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.


Demo  Demos\LayerEditing\MagicFillToPolygon\Magic2Polygon.dpr


// Create a new polygon layer when the user clicks on the image
procedure TForm1.ImageEnView1MouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
  ImageEnView1.SelectionBase := iesbClientArea;
  ImageEnView1.LayersCreateFromEdge( X, Y, 25, true );
  TIEPolyLineLayer( ImageEnView1.CurrentLayer ).LineColor := clBlack;
  TIEPolyLineLayer( ImageEnView1.CurrentLayer ).FillColor := clNone;

// 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

See Also

- SmoothJaggedEdges
- SimplifyPolygon
- LayersCreatePolylineFromSelection