Help Center

CGpGraphicsPathIterator.NextPathTypemethod

Gets the starting index and the ending index of the next group of data points that all have the same type.

GraphicsmethodCGpGraphics.incdocumented

Syntax

FUNCTION NextPathType (BYVAL pathType AS BYTE PTR, BYVAL startIndex AS INT_ PTR, BYVAL endIndex AS INT_ PTR) AS INT

Parameters

NameDescription
pathTypePointer to a BYTE that receives the point type shared by all points in the group. Possible values are PathPointTypeLine and PathPointTypeBezier, which are elements of the PathPointType enumeration.
startIndexPointer to an LONG that receives the starting index of the group of points.
endIndexPointer to an LONG that receives the ending index of the group of points.

Return value

This method returns the number of data points in the group. If there are no more groups in the path, this method returns 0.

Description

Gets the starting index and the ending index of the next group of data points that all have the same type.

Remarks

A path has an array of data points that define its lines and curves. All curves in the path are represented as Bézier splines, so a given point in the array has one of two types: PathPointTypeLine or PathPointTypeBezier.

The first time you call the NextSubpath method of an iterator, it gets the starting and ending indices of the first group of points that all have the same type. The second time, it gets the second group, and so on. Each time you call NextSubpath, it returns the number of data points in the obtained group. When there are no groups remaining, it returns 0.

Example

' ======================================================================================== ' Example: Using GdipPathIterNextPathType to Group Points by Type. ' Helps you understand how a path is constructed—lines vs. curves. ' Enables selective rendering, editing, or flattening based on segment type. ' Returns StatusOk, but resultCount 0. ' ======================================================================================== SUB Example_PathIterNextPathType (BYVAL hdc AS HDC)

DIM hStatus AS LONG

' // Create a graphics object from the device context DIM graphics AS GpGraphics PTR hStatus = GdipCreateFromHDC(hdc, @graphics)

' // Get the DPI scaling ratios DIM dpiX AS SINGLE hStatus = GdipGetDpiX(graphics, @dpiX) DIM rxRatio AS SINGLE = dpiX / 96 DIM dpiY AS SINGLE hStatus = GdipGetDpiY(graphics, @dpiY) Dim ryRatio AS SINGLE = dpiY / 96 ' // Set the scale transform hStatus = GdipScaleWorldTransform(graphics, rxRatio, ryRatio, MatrixOrderPrepend)

' Create a GraphicsPath with grouped types DIM path AS GpPath PTR hStatus = GdipCreatePath(FillModeAlternate, @path)

' Add 3 lines (same type group) hStatus = GdipAddPathLine(path, 20, 20, 120, 20) hStatus = GdipAddPathLine(path, 120, 20, 70, 100) hStatus = GdipAddPathLine(path, 70, 100, 20, 20)

' Add Bézier curve (new type group) hStatus = GdipAddPathBezier(path, 150, 30, 180, 10, 210, 50, 240, 30)

' Create PathIterator DIM iterator AS GpPathIterator PTR hStatus = GdipCreatePathIter(@iterator, path)

' Create font and brush DIM fontFamily AS GpFontFamily PTR DIM font AS GpFont PTR DIM brush AS GpSolidFill PTR hStatus = GdipCreateFontFamilyFromName("Arial", NULL, @fontFamily) hStatus = GdipCreateFont(fontFamily, AfxGdipPointsToPixels(12, TRUE), FontStyleRegular, UnitPixel, @font) hStatus = GdipCreateSolidFill(ARGB_BLACK, @brush)

' Iterate through path types DIM resultCount AS LONG, pathType AS BYTE DIM startIdx AS LONG, endIdx AS LONG DIM yOffset AS SINGLE = 10.0 DIM segmentIndex AS LONG = 1

DO

hStatus = GdipPathIterNextPathType(iterator, @resultCount, @pathType, @startIdx, @endIdx)
  IF resultCount = 0 THEN EXIT DO

  DIM typeName AS STRING
  SELECT CASE pathType AND &H07
     CASE PathPointTypeStart
        typeName = "Start"
     CASE PathPointTypeLine
        typeName = "Line"
     CASE PathPointTypeBezier
        typeName = "Bezier"
     CASE ELSE
        typeName = "Unknown"
  END SELECT

  DIM info AS STRING
  info = "Segment " & segmentIndex & ": Type=" & typeName & ", Start=" & startIdx & ", End=" & endIdx
  DIM layout AS GpRectF = (10.0, yOffset, 400.0, 20.0)
  hStatus = GdipDrawString(graphics, info, -1, font, @layout, NULL, brush)

  yOffset += 20.0
  segmentIndex += 1

LOOP

' Cleanup IF brush THEN GdipDeleteBrush(brush) IF font THEN GdipDeleteFont(font) IF fontFamily THEN GdipDeleteFontFamily(fontFamily) IF iterator THEN GdipDeletePathIter(iterator) IF path THEN GdipDeletePath(path) IF graphics THEN GdipDeleteGraphics(graphics)

END SUB ' ========================================================================================

Reference

  • Include file CGpGraphics.inc
  • Defined in AfxNova/CGpPath.inc:678
  • Documented in Graphics/GdiPlus Classes/CGpGraphics Classes.md
  • Topic: CGpGraphics Class