PathGradientBrush::SetTransform 方法 (gdipluspath.h)

PathGradientBrush::SetTransform 方法會設定此路徑漸層筆刷的轉換矩陣。

語法

Status SetTransform(
  [in] const Matrix *matrix
);

參數

[in] matrix

類型: const 矩陣*

指定轉換矩陣之 Matrix 物件的指標。

傳回值

類型: 狀態

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

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

備註

PathGradientBrush 物件具有 GraphicsPath 物件,可作為筆刷的界限路徑。 當您使用路徑漸層筆刷繪製時,只會填滿界限路徑內的區域。 如果筆刷的轉換矩陣設定為代表身分識別以外的任何轉換,則界限路徑會在轉譯期間根據該矩陣轉換,而且只會填滿轉換路徑內的區域。

轉換僅適用於轉譯期間。 PathGradientBrush 物件所儲存的界限路徑不會由 PathGradientBrush::SetTransform 方法改變。

範例

下列範例會根據三角形路徑建立 PathGradientBrush 物件。 Graphics::FillRectangle 方法會使用路徑漸層筆刷繪製包含三角形路徑的矩形。 接下來,程式代碼會建立 代表 複合轉換 (旋轉的 Matrix 物件,然後轉譯) 並將該 Matrix 物件的地址傳遞至 PathGradientBrush::SetTransform方法 PathGradientBrush 物件。 程序代碼會再次呼叫 FillRectangle ,以使用轉換的路徑漸層筆刷繪製相同的矩形。

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

   Point pts[] = {
      Point(0, 0), 
      Point(100, 0), 
      Point(100, 100)};

   Color cols[] = {
      Color(255, 255, 0, 0),  // red
      Color(255, 0, 255, 0),  // green
      Color(255, 0, 0, 0)};   // black

   INT count = 3;
   PathGradientBrush pthGrBrush(pts, 3);
   pthGrBrush.SetSurroundColors(cols, &count);

   // Fill an area with the path gradient brush (no transformation).
   graphics.FillRectangle(&pthGrBrush, 0, 0, 200, 200);

   // Set the transformation for the brush (rotate, then translate).
   Matrix matrix(0.0f, 1.0f, -1.0f, 0.0f, 150.0f, 60.0f);
   pthGrBrush.SetTransform(&matrix);
   
   // Fill the same area with the transformed path gradient brush.
   graphics.FillRectangle(&pthGrBrush, 0, 0, 200, 200);  
}

規格需求

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

另請參閱

筆刷和填滿的圖形

建立路徑漸層

使用色彩漸層填滿圖形

GraphicsPath

PathGradientBrush

PathGradientBrush::GetTransform

PathGradientBrush::MultiplyTransform

PathGradientBrush::ResetTransform

PathGradientBrush::RotateTransform

PathGradientBrush::ScaleTransform

PathGradientBrush::TranslateTransform