如何調整物件

本主題描述如何使用 Matrix3x2F 類別來調整物件。 若要調整物件,表示讓物件變大或更小。 您可以呼叫下列兩種方法之一來調整物件。

  • Matrix3x2F::Scale (D2D1_SIZE_F scalefactor,D2D1_POINT_2F centerpoint)
  • Matrix3x2F::Scale (float scalex、 float scaley, D2D1_POINT_2F centerpoint)

第一種方法會將 scalexscaley 儲存為 D2D1_SIZE_F 結構中已排序的浮點值組。 第二種方法會將 scalexscaley 定義為個別參數。

無論您使用哪種方法,都必須同時指定 scalexscaley 因數。 scalex值是 x 方向的縮放比例。 例如, 縮放比例 值為 1.5 會將物件延展至 X 軸的 150%。 同樣地,縮放值是 Y 方向的 縮放 比例。 例如, 縮放 值 0.5 會沿著 y 軸將物件的高度縮小 50%。

若要將點指定為縮放作業的中心,請使用 centerpoint 參數。 根據預設,物件會以其來源為中心, (0,0) 。

下列範例程式碼會建立縮放轉換,將正方形的大小增加到原始大小的 130%。 中心點會設定為原始方塊的左上角。

    // Create a rectangle.
    D2D1_RECT_F rectangle = D2D1::Rect(438.0f, 80.5f, 498.0f, 140.5f);

    // Draw the outline of the rectangle.
    m_pRenderTarget->DrawRectangle(
        rectangle,
        m_pOriginalShapeBrush,
        1.0f,
        m_pStrokeStyleDash
        );

    // Apply the scale transform to the render target.
    m_pRenderTarget->SetTransform(
        D2D1::Matrix3x2F::Scale(
            D2D1::Size(1.3f, 1.3f),
            D2D1::Point2F(438.0f, 80.5f))
        );

    // Paint the rectangle's interior.
    m_pRenderTarget->FillRectangle(rectangle, m_pFillBrush);

    // Draw the outline of the rectangle.
    m_pRenderTarget->DrawRectangle(rectangle, m_pTransformedShapeBrush);

下圖顯示將縮放轉換套用至平方的效果。 原始方形是虛線外框,而縮放方塊是實心外框。

正方形大小調整為原始大小的 130%。

Direct2D 轉換概觀

Direct2D 參考