Path.GetContour Method (Bitmap, Channel, Single)

Applies to: Graphics Mill 12.1, 6.x-12.x (may differ)

Gets the contour of the region where the specified channel of a bitmap reaches the specified level.

Namespace: Aurigma.GraphicsMill.Drawing
Assembly: Aurigma.GraphicsMill (in Aurigma.GraphicsMill.dll)

Syntax

C#
public static Path GetContour(
	Bitmap bitmap,
	Channel channel,
	float level
)

Parameters

bitmap

Type: Aurigma.GraphicsMill.Bitmap

A bitmap to find the contour in.
channel

Type: Aurigma.GraphicsMill.Channel

The channel to trace.
level

Type: System.Single

The level as a fraction of the largest channel value, greater than 0 and not greater than 1.

Return Value

A Path object that contains one closed subpath for each outer boundary and each hole. It is empty (never null) when no pixel reaches the level.

Remarks

The contour has sub-pixel accuracy. Its points are interpolated between pixel centers, so anti-aliased edges and soft masks give smooth lines. GetAlphaContour() follows pixel edges, so its contour has steps.

The pixel (x, y) covers the area from x to x + 1 and from y to y + 1. Pixels outside the bitmap count as 0, so a region that touches the border is closed just outside the bitmap.

You can trace any channel of any pixel format except the spot ones. Alpha of a bitmap without an alpha channel is 1 everywhere. An indexed bitmap is traced in the colors and alpha of its palette.

All subpaths have consistent directions, so you can fill the contour with either filling rule.

The contours of this method and of GetAlphaContour() are offset by half a pixel from each other. Do not mix the contours of the two methods.

Examples

C#
// Trace the alpha channel at 50% with sub-pixel accuracy.
var contour = Path.GetContour(image, Channel.Alpha, 0.5f);

The contours that GetAlphaContour and GetContour return for a small image of a circle, scaled four times.

The contours that GetAlphaContour and GetContour return for a small image of a circle, scaled four times.

Exceptions

Exception Condition
System.ArgumentNullException The bitmap is null.
System.ArgumentOutOfRangeException The channel is not defined, or the level is out of range.

See Also

Reference

Manual