Help Center

GdipWarpPathfunction

Applies a warp transformation to this path. This function also flattens (converts to a sequence of straight lines) the path.

Graphicsfunctiondocumented

Syntax

FUNCTION GdipWarpPath (BYVAL path AS GpPath PTR, BYVAL matrix AS GpMatrix PTR, BYVAL points AS CONST GpPointF PTR, BYVAL count AS INT_, BYVAL srcx AS REAL, BYVAL srcy AS REAL, BYVAL srcwidth AS REAL, BYVAL srcheight AS REAL, BYVAL warpMode AS WarpMode, BYVAL flatness AS REAL) AS GpStatus

Parameters

NameDescription
path[in] Pointer to the GraphicsPath object.
matrix[in] Pointer to a Matrix object that represents a transformation to be applied along with the warp. If this parameter is NULL, no transformation is applied. The default value is NULL.
points[in] Pointer to an array of points that, along with the srcRect parameter, defines the warp transformation.
count[in] Long integer value that specifies the number of points in the destPoints array. The value of this parameter must be 3 or 4.
srcx[in] Simple precision value that specifies the x-coordinate of the upper-left corner of the rectangle that, along with the destPoints parameter, defines the warp transformation.
srcy[in] Simple precision value that specifies the y-coordinate of the upper-left corner of the rectangle that, along with the destPoints parameter, defines the warp transformation.
srcwidth[in] Simple precision value that specifies the width of the rectangle that, along with the destPoints parameter, defines the warp transformation.
srcheight[in] Real number that specifies the height of the rectangle that, along with the destPoints parameter, defines the warp transformation.
warpMode[in] Element of the WarpMode enumeration that specifies the kind of warp to be applied. The default value is WarpModePerspective.
flatness[in] Simple precision value that influences the number of line segments that are used to approximate the original path. Small values specify that many line segments are used, and large values specify that few line segments are used. The default value is FlatnessDefault.

Description

Applies a warp transformation to this path. This functtion also flattens (converts to a sequence of straight lines) the path.

Remarks

A GraphicsPath object stores a collection of data points that represent lines and curves. The GdipWarpPath function converts those data points so that they represent only lines. The flatness parameter influences the number of lines that are stored. The original data points that represented curves are lost.

If the count parameter has a value of 4, the warp transformation is defined as shown in the following table.

A transformation specified by a source rectangle and four destination points is capable of mapping a rectangle to an arbitrary quadrilateral that is not necessarily a parallelogram.

If the count parameter has a value of 3, the warp transformation is defined as shown in the following table.

A transformation specified by a source rectangle and three destination points maps rectangles to parallelograms.

Example

' ======================================================================================== ' The following example creates a GraphicsPath object and adds a closed figure to the path. ' The code defines a warp transformation by specifying a source rectangle and an array of ' four destination points. The source rectangle and destination points are passed to the ' GdipWarpPath function. The code draws the path twice: once before it has been warped and ' once after it has been warped. ' ======================================================================================== SUB Example_WarpPath (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 path DIM path AS GpPath PTR hStatus = GdipCreatePath(FillModeAlternate, @path)

DIM pts(7) AS GpPointF pts(0).x = 20 : pts(0).y = 60 pts(1).x = 30 : pts(1).y = 90 pts(2).x = 15 : pts(2).y = 110 pts(3).x = 15 : pts(3).y = 145 pts(4).x = 55 : pts(4).y = 145 pts(5).x = 55 : pts(5).y = 110 pts(6).x = 40 : pts(6).y = 90 pts(7).x = 50 : pts(7).y = 60

hStatus = GdipAddPathLine2(path, @pts(0), 8) hStatus = GdipClosePathFigure(path)

' // Draw the path before applying a warp transformation. DIM bluePen AS GpPen PTR hStatus = GdipCreatePen1(ARGB_BLUE, 1, UnitWorld, @bluePen) hStatus = GdipDrawPath(graphics, bluePen, path)

' // Define a warp transformation, and warp the path. DIM srcRect AS GpRectF = (10, 50, 50, 100)

' // Destinations points DIM destPts(3) AS GpPointF destPts(0).x = 220 : destPts(0).y = 10 destPts(1).x = 280 : destPts(1).y = 10 destPts(2).x = 100 : destPts(2).y = 150 destPts(3).x = 400 : destPts(3).y = 150

' // Warp the path hStatus = GdipWarpPath(path, NULL, @destPts(0), 4, srcRect.x, srcRect.y, srcRect.Width, srcRect.Height, WarpModePerspective, FlatnessDefault)

' // Draw the warped path. hStatus = GdipDrawPath(graphics, bluePen, path)

' // Draw the source rectangle and the destination polygon. DIM blackPen AS GpPen PTR hStatus = GdipCreatePen1(ARGB_BLACK, 1, UnitWorld, @blackPen) hStatus = GdipDrawRectangle(graphics, blackPen, srcRect.x, srcRect.y, srcRect.Width, srcRect.Height) hStatus = GdipDrawLine(graphics, blackPen, destpts(0).x, destPts(0).y, destPts(1).x, destPts(1).y) hStatus = GdipDrawLine(graphics, blackPen, destpts(0).x, destPts(0).y, destPts(2).x, destPts(2).y) hStatus = GdipDrawLine(graphics, blackPen, destpts(1).x, destPts(1).y, destPts(3).x, destPts(3).y) hStatus = GdipDrawLine(graphics, blackPen, destpts(2).x, destPts(2).y, destPts(3).x, destPts(3).y)

' // Cleanup IF bluePen THEN GdipDeletePen(bluePen) IF blackPen THEN GdipDeletePen(blackPen) IF path THEN GdipDeletePath(path) IF graphics THEN GdipDeleteGraphics(graphics)

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

Reference

  • Defined in AfxNova/AfxGdiPlus.bi:2052
  • Documented in Graphics/GdiPlus Flat Api/GdiPlusGraphicsPath.md
  • Topic: GraphicsPath Functions