GraphicsPath::Warp 方法 (gdipluspath.h)

GraphicsPath::Warp 方法會將變形轉換套用至此路徑。 GraphicsPath::Warp 方法也會將 (轉換成路徑) 直線序列。

語法

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

參數

[in] destPoints

類型: const PointF*

指向點陣列的指標,連同 srcRect 參數會定義變形。

[in] count

類型: INT

指定 destPoints 陣列中點數的整數。 此參數的值必須是 3 或 4。

[in, ref] srcRect

類型: const RectF

destPoints 參數一起定義變形轉換的矩形參考。

[in] matrix

類型: const 矩陣*

選擇性。 Matrix 物件的指標,代表要與變形一起套用的轉換。 如果此參數為 NULL,則不會套用轉換。 預設值是 NULL

[in] warpMode

類型: WarpMode

選擇性。 WarpMode 列舉的 元素,指定要套用的變形種類。 預設值為 WarpModePerspective。

[in] flatness

類型: REAL

選擇性。 影響用來近似原始路徑之行段數目的實數。 小數值會指定使用許多線條線段,而大值則指定使用幾行線段。 默認值為 FlatnessDefault,這是 Gdiplusenums.h 中定義的常數。

傳回值

類型: 狀態

如果方法成功,它會傳回Ok,這是 Status 列舉的元素。

如果方法失敗,它會傳回 Status 列舉的其他其中一個專案。

備註

GraphicsPath 物件會儲存代表線條和曲線的數據點集合。 GraphicsPath::Warp 方法會轉換這些數據點,使其只代表線條。 平面參數會影響儲存的行數。 代表曲線的原始數據點會遺失。

如果 count 參數的值為 4,則會定義變形轉換,如下表所示。

來源點 目的地點
srcRect 左上角 destPoints[0]
srcRect 右上角 destPoints[1]
srcRect 的左下角 destPoints[2]
srcRect 右下角 destPoints[3]
 

來源矩形和四個目的點所指定的轉換,能夠將矩形對應至不一定是平行投影的任意四邊形。

如果 count 參數的值為 3,則會定義變形轉換,如下表所示。

來源點 目的地點
srcRect 左上角 destPoints[0]
srcRect 右上角 destPoints[1]
srcRect 的左下角 destPoints[2]
 

來源矩形所指定的轉換,而三個目的點會將矩形對應至平行投影。

範例

下列範例會建立 GraphicsPath 物件,並將封閉的圖形新增至路徑。 程式代碼會藉由指定來源矩形和四個目的地點的數位來定義變形轉換。 來源矩形和目的點會傳遞至 Warp 方法。 程序代碼會繪製路徑兩次:在變形之前,一次,一次經過變形之後。


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]);
}

規格需求

需求
最低支援的用戶端 Windows XP、Windows 2000 Professional [僅限桌面應用程式]
最低支援的伺服器 Windows 2000 Server [僅限桌面應用程式]
目標平台 Windows
標頭 gdipluspath.h (包含 Gdiplus.h)
程式庫 Gdiplus.lib
Dll Gdiplus.dll

另請參閱

使用區域裁剪

建構和繪製路徑

建立路徑漸層

壓平合併路徑

GraphicsPath

GraphicsPath::Flatten

GraphicsPath::Outline

GraphicsPath::Widen

矩陣

路徑

WarpMode