Help Center

CGpLinearGradientBrush.TranslateTransformmethod

Updates this brush's current transformation matrix with the product of itself and a translation matrix.

GraphicsmethodCGpBrush.incdocumented

Syntax

FUNCTION TranslateTransform (BYVAL dx AS SINGLE, BYVAL dy AS SINGLE, BYVAL order AS MatrixOrder = MatrixOrderPrepend) AS GpStatus

Parameters

NameDescription
dxSingle precision number that specifies the horizontal component of the translation.
dySingle precision number that specifies the vertical component of the translation.
orderOptional. Element of the MatrixOrder enumeration that specifies the order of multiplication. MatrixOrderPrepend specifies that the passed matrix is on the left, and MatrixOrderAppend specifies that the passed matrix is on the right. The default value is MatrixOrderPrepend.

Return value

If the function succeeds, it returns Ok, which is an element of the GpStatus enumeration.

If the function fails, it returns one of the other elements of the GpStatus enumeration.

Description

Updates this brush's current transformation matrix with the product of itself and a translation matrix.

Remarks

A single 3×3 matrix can store any sequence of affine transformations. If you have several 3×3 matrices, each of which represents an affine transformation, the product of those matrices is a single 3×3 matrix that represents the entire sequence of transformations. The transformation represented by that product is called a composite transformation. For example, suppose matrix S represents a scaling, and matrix T represents a translation. If matrix M is the product ST, then matrix M represents a composite transformation: first scale, then translate.

The order of matrix multiplication is important. In general, the matrix product RT is not the same as the matrix product TR. In the example given in the previous paragraph, the composite transformation represented by RT (first rotate, then translate) is not the same as the composite transformation represented by TR (first translate, then rotate).

Example

' ======================================================================================== ' The following example creates a linear gradient brush and uses it to fill a rectangle. ' Next, the code modifies the brush's transformation matrix, applying a composite transformation, ' and then fills a rectangle with the transformed brush. ' ======================================================================================== SUB Example_TranslateTransform (BYVAL hdc AS HDC)

' // Create a graphics object from the window device context DIM graphics AS CGpGraphics = hdc ' // Set the scale transform graphics.ScaleTransformForDpi

DIM rc AS GpRect = (0, 0, 80, 40) DIM linGrBrush AS CGpLinearGradientBrush = CGpLinearGradientBrush(@rc, _

ARGB_RED, ARGB_BLUE, LinearGradientModeHorizontal)

' // Fill a large area with the gradient brush (no transformation). graphics.FillRectangle(@linGrBrush, 0, 0, 800, 150)

' // Apply a composite transformation: first scale, then translate. linGrBrush.ScaleTransform(2, 1) ' // horizontal doubling linGrBrush.TranslateTransform(30, 0, MatrixOrderAppend) ' // translation

' // Fill a large area with the transformed linear gradient brush. graphics.FillRectangle(@linGrBrush, 0, 200, 800, 150)

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

Reference

  • Include file CGpBrush.inc
  • Defined in AfxNova/CGpBrush.inc:487
  • Documented in Graphics/GdiPlus Classes/CGpBrush Classes.md
  • Topic: CGpBrush Class