The following example creates a linear gradient brush and uses it to fill a rectangle. Next, the code sets the brush's transformation matrix, fills a rectangle with the transformed brush, modifies the brush's transformation matrix, and again fills a rectangle with the transformed brush.
C++
VOID Example_MultTrans(HDC hdc)
{
Graphics myGraphics(hdc);
Matrix S(2, 0, 0, 1, 0, 0); // horizontal doubling
Matrix T(1, 0, 0, 1, 50, 0); // horizontal translation of 50 units
LinearGradientBrush linGrBrush(
Rect(0, 0, 200, 100),
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255), // blue
LinearGradientModeHorizontal);
// Fill a large area with the gradient brush (no transformation).
myGraphics.FillRectangle(&linGrBrush, 0, 0, 800, 100);
// Apply the scaling transformation.
linGrBrush.SetTransform(&S);
// Fill a large area with the scaled gradient brush.
myGraphics.FillRectangle(&linGrBrush, 0, 150, 800, 100);
// Form a composite transformation: first scale, then translate.
linGrBrush.MultiplyTransform(&T, MatrixOrderAppend);
// Fill a large area with the scaled and translated gradient brush.
myGraphics.FillRectangle(&linGrBrush, 0, 300, 800, 100);
}
PowerBASIC
SUB GDIP_MultiplyLineTransform (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pLinBrush AS DWORD
LOCAL rc AS RECTF
LOCAL colorRed AS DWORD
LOCAL colorBlue AS DWORD
LOCAL S AS DWORD
LOCAL T AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateMatrix2(2, 0, 0, 1, 0, 0, S) ' // horizontal doubling
hStatus = GdipCreateMatrix2(1, 0, 0, 1, 50, 0, T) ' // horizontal translation of 50 units
rc.x = 0 : rc.y = 0 : rc.Width = 200 : rc.Height = 100
colorRed = GDIP_ARGB(255, 255, 0, 0)
colorBlue = GDIP_ARGB(255, 0, 0, 255)
hStatus = GdipCreateLineBrushFromRect(rc, colorRed, colorBlue, %LinearGradientModeHorizontal, %WrapModeTile, pLinBrush)
' // Fill a large area with the gradient brush (no transformation).
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 800, 100)
' // Apply the scaling transformation.
hStatus = GdipSetLineTransform(pLinBrush, S)
' // Fill a large area with the scaled gradient brush.
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 150, 800, 100)
' // Form a composite transformation: first scale, then translate.
hStatus = GdipMultiplyLineTransform(pLinBrush, T, %MatrixOrderAppend)
' // Fill a large area with the scaled and translated gradient brush.
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 300, 800, 100)
' // Cleanup
IF S THEN GdipDeleteMatrix(S)
IF T THEN GdipDeleteMatrix(T)
IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipMultiplyLineTransform.png)