CGpGraphicsPathIterator.HasCurvemethod
Determines whether the path has any curves.
Syntax
FUNCTION HasCurve () AS BOOLEAN
Return value
If the path has at least one curve, this method returns TRUE; otherwise, it returns FALSE.
Description
Determines whether the path has any curves.
Remarks
All curves in a path are stored as sequences of Bézier splines. For example, when you add an ellipse to a path, you specify the upper-left corner, the width, and the height of the ellipse's bounding rectangle. Those numbers (upper-left corner, width, and height) are not stored in the path; instead; the ellipse is converted to a sequence of four Bézier splines. The path stores the endpoints and control points of those Bézier splines.
A path stores an array of data points, each of which belongs to a line or a Bézier spline. If some of the points in the array belong to Bézier splines, then HasCurve returns TRUE. If all points in the array belong to lines, then HasCurve returns FALSE.
Certain methods flatten a path, which means that all the curves in the path are converted to sequences of lines. After a path has been flattened, HasCurve will always return FALSE. Flattening happens when you call the Flatten, Widen, or Warp method of the GraphicsPath class.
Example
' ======================================================================================== ' Using the HasCurve method to detect Bézier segments. ' Paths with curves are stored as Bézier splines. ' Some operations (like flattening or widening) convert curves to straight lines. ' This check helps you decide whether to preserve or simplify the path. ' ======================================================================================== SUB Example_PathIterHasCurve (BYVAL hdc AS HDC)
' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi
' // Create a GraphicsPath DIM path AS CGpGraphicsPath path.AddLine(20, 20, 120, 20) path.AddBezier(130, 30, 160, 10, 190, 50, 220, 30)
' // Create a GraphicsPathIterator DIM iterator AS CGpGraphicsPathIterator = @path
' // Check if the path contains curves DIM hasCurve AS BOOLEAN = iterator.HasCurve
' // Create font and brush for displaying the result DIM fontFamily AS CGpFontFamily = CGpFontFamily("Arial") DIM font AS CGpFont = CGpFont(@fontFamily, AfxGdipPointsToPixels(16, TRUE), FontStyleRegular) DIM brush AS CGpSolidBrush = ARGB_BLACK
' Draw the result as a string DIM info AS STRING = "Path contains curves: " & IIF(hasCurve, "True", "False") DIM layout AS GpRectF = (10.0, 10.0, 300.0, 20.0) graphics.DrawString(info, -1, @font, @layout, @brush)
END SUB ' ========================================================================================
Reference
- Include file
CGpGraphics.inc - Defined in AfxNova/CGpPath.inc:726
- Documented in Graphics/GdiPlus Classes/CGpGraphics Classes.md
- Topic: CGpGraphics Class