GraphicsPath::Warp method

The GraphicsPath::Warp method applies a warp transformation to this path. The GraphicsPath::Warp method also flattens (converts to a sequence of straight lines) the path.

Syntax

Status Warp(
  IN const PointF  *destPoints,
  IN INT           count,
  IN const RectF & srcRect,
  IN const Matrix  *matrix,
  IN WarpMode      warpMode,
  IN REAL          flatness
);

Parameters

destPoints

Type: const PointF*

Pointer to an array of points that, along with the srcRect parameter, defines the warp transformation.

count

Type: INT

Integer that specifies the number of points in the destPoints array. The value of this parameter must be 3 or 4.

srcRect

Type: const RectF

Reference to a rectangle that, along with the destPoints parameter, defines the warp transformation.

matrix

Type: const Matrix*

Optional. 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.

warpMode

Type: WarpMode

Optional. Element of the WarpMode enumeration that specifies the kind of warp to be applied. The default value is WarpModePerspective.

flatness

Type: REAL

Optional. Real number 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, which is a constant defined in Gdiplusenums.h.

Return Value

Type: Type: Status

If the method succeeds, it returns Ok, which is an element of the Status enumeration.

If the method fails, it returns one of the other elements of the Status enumeration.

Remarks

A GraphicsPath object stores a collection of data points that represent lines and curves. The GraphicsPath::Warp method 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.

Source point Destination point
Upper-left corner of srcRect destPoints[0]
Upper-right corner of srcRect destPoints[1]
Lower-left corner of srcRect destPoints[2]
Lower-right corner of srcRect destPoints[3]
 

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.

Source point Destination point
Upper-left corner of srcRect destPoints[0]
Upper-right corner of srcRect destPoints[1]
Lower-left corner of srcRect destPoints[2]
 

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

Examples

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 Warp method. The code draws the path twice: once before it has been warped and once after it has been warped.


VOID WarpExample(HDC hdc)
{
   Graphics graphics(hdc);

   // Create a path.
   PointF points[] ={
      PointF(20.0f, 60.0f),
      PointF(30.0f, 90.0f),
      PointF(15.0f, 110.0f),
      PointF(15.0f, 145.0f),
      PointF(55.0f, 145.0f),
      PointF(55.0f, 110.0f),
      PointF(40.0f, 90.0f),
      PointF(50.0f, 60.0f)};

   GraphicsPath path;
   path.AddLines(points, 8);
   path.CloseFigure();

   // Draw the path before applying a warp transformation.
   Pen bluePen(Color(255, 0, 0, 255));
   graphics.DrawPath(&bluePen, &path);

   // Define a warp transformation, and warp the path.
   RectF srcRect(10.0f, 50.0f, 50.0f, 100.0f);

   PointF destPts[] = {
      PointF(220.0f, 10.0f),
      PointF(280.0f, 10.0f),
      PointF(100.0f, 150.0f),
      PointF(400.0f, 150.0f)};

   path.Warp(destPts, 4, srcRect);

   // Draw the warped path.
   graphics.DrawPath(&bluePen, &path);

   // Draw the source rectangle and the destination polygon.
   Pen blackPen(Color(255, 0, 0, 0));
   graphics.DrawRectangle(&blackPen, srcRect);
   graphics.DrawLine(&blackPen, destPts[0], destPts[1]);
   graphics.DrawLine(&blackPen, destPts[0], destPts[2]);
   graphics.DrawLine(&blackPen, destPts[1], destPts[3]);
   graphics.DrawLine(&blackPen, destPts[2], destPts[3]);
}

Requirements

   
Minimum supported client Windows XP, Windows 2000 Professional [desktop apps only]
Minimum supported server Windows 2000 Server [desktop apps only]
Target Platform Windows
Header gdipluspath.h (include Gdiplus.h)
Library Gdiplus.lib
DLL Gdiplus.dll

See Also

Clipping with a Region

Constructing and Drawing Paths

Creating a Path Gradient

Flattening Paths

GraphicsPath

GraphicsPath::Flatten

GraphicsPath::Outline

GraphicsPath::Widen

Matrix

Paths

WarpMode