<PackageReference Include="System.Drawing.Common" Version="9.0.0-rc.1.24451.1" />

GraphicsPathIterator

Provides the ability to iterate through subpaths in a GraphicsPath and test the types of shapes contained in each subpath. This class cannot be inherited.
using System.Runtime.CompilerServices; using Windows.Win32; using Windows.Win32.Foundation; using Windows.Win32.Graphics.GdiPlus; namespace System.Drawing.Drawing2D { public sealed class GraphicsPathIterator : MarshalByRefObject, IDisposable { internal unsafe GpPathIterator* _nativeIterator; public unsafe int Count { get { int result = default(int); PInvoke.GdipPathIterGetCount(_nativeIterator, &result).ThrowIfFailed(); GC.KeepAlive(this); return result; } } public unsafe int SubpathCount { get { int result = default(int); PInvoke.GdipPathIterGetSubpathCount(_nativeIterator, &result).ThrowIfFailed(); GC.KeepAlive(this); return result; } } [NullableContext(2)] public unsafe GraphicsPathIterator(GraphicsPath path) { GpPathIterator* nativeIterator = default(GpPathIterator*); PInvoke.GdipCreatePathIter(&nativeIterator, path.Pointer()).ThrowIfFailed(); GC.KeepAlive(path); _nativeIterator = nativeIterator; } public void Dispose() { Dispose(true); GC.SuppressFinalize(this); } private unsafe void Dispose(bool disposing) { if (_nativeIterator != null) try { PInvoke.GdipDeletePathIter(_nativeIterator); } catch (Exception ex) { if (ClientUtils.IsSecurityOrCriticalException(ex)) throw; } finally { _nativeIterator = null; } } ~GraphicsPathIterator() { Dispose(false); } public unsafe int NextSubpath(out int startIndex, out int endIndex, out bool isClosed) { fixed (int* startIndex2 = &startIndex) { fixed (int* endIndex2 = &endIndex) { int result = default(int); BOOL value = default(BOOL); PInvoke.GdipPathIterNextSubpath(_nativeIterator, &result, startIndex2, endIndex2, &value).ThrowIfFailed(); isClosed = value; GC.KeepAlive(this); return result; } } } [NullableContext(1)] public unsafe int NextSubpath(GraphicsPath path, out bool isClosed) { int result = default(int); BOOL value = default(BOOL); PInvoke.GdipPathIterNextSubpathPath(_nativeIterator, &result, path.Pointer(), &value).ThrowIfFailed(); isClosed = value; GC.KeepAlive(this); return result; } public unsafe int NextPathType(out byte pathType, out int startIndex, out int endIndex) { fixed (byte* pathType2 = &pathType) { fixed (int* startIndex2 = &startIndex) { fixed (int* endIndex2 = &endIndex) { int result = default(int); PInvoke.GdipPathIterNextPathType(_nativeIterator, &result, pathType2, startIndex2, endIndex2).ThrowIfFailed(); GC.KeepAlive(this); return result; } } } } public unsafe int NextMarker(out int startIndex, out int endIndex) { fixed (int* startIndex2 = &startIndex) { fixed (int* endIndex2 = &endIndex) { int result = default(int); PInvoke.GdipPathIterNextMarker(_nativeIterator, &result, startIndex2, endIndex2).ThrowIfFailed(); GC.KeepAlive(this); return result; } } } [NullableContext(1)] public unsafe int NextMarker(GraphicsPath path) { int result = default(int); PInvoke.GdipPathIterNextMarkerPath(_nativeIterator, &result, path.Pointer()).ThrowIfFailed(); GC.KeepAlive(this); return result; } public unsafe bool HasCurve() { BOOL value = default(BOOL); PInvoke.GdipPathIterHasCurve(_nativeIterator, &value).ThrowIfFailed(); GC.KeepAlive(this); return value; } public unsafe void Rewind() { PInvoke.GdipPathIterRewind(_nativeIterator).ThrowIfFailed(); GC.KeepAlive(this); } [NullableContext(1)] public int Enumerate(ref PointF[] points, ref byte[] types) { return Enumerate(points.OrThrowIfNull("points").AsSpan(), types.OrThrowIfNull("types").AsSpan()); } public unsafe int Enumerate(Span<PointF> points, Span<byte> types) { if (points.Length != types.Length || points.Length < Count) throw Status.InvalidParameter.GetException(); if (points.Length != 0) { fixed (PointF* points2 = &points.GetPinnableReference()) { fixed (byte* types2 = &types.GetPinnableReference()) { int result = default(int); PInvoke.GdipPathIterEnumerate(_nativeIterator, &result, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, types2, points.Length).ThrowIfFailed(); GC.KeepAlive(this); return result; } } } return 0; } [NullableContext(1)] public int CopyData(ref PointF[] points, ref byte[] types, int startIndex, int endIndex) { return CopyData(points.OrThrowIfNull("points").AsSpan(), types.OrThrowIfNull("types").AsSpan(), startIndex, endIndex); } public unsafe int CopyData(Span<PointF> points, Span<byte> types, int startIndex, int endIndex) { int num = endIndex - startIndex + 1; if (points.Length == types.Length && endIndex >= 0 && startIndex >= 0 && endIndex >= startIndex && num <= points.Length && endIndex < Count) { fixed (PointF* points2 = &points.GetPinnableReference()) { fixed (byte* types2 = &types.GetPinnableReference()) { int result = default(int); PInvoke.GdipPathIterCopyData(_nativeIterator, &result, (global::Windows.Win32.Graphics.GdiPlus.PointF*)points2, types2, startIndex, endIndex).ThrowIfFailed(); GC.KeepAlive(this); return result; } } } throw Status.InvalidParameter.GetException(); } } }