The following example creates a linear gradient brush and uses it to fill a rectangle. Next, the code modifies the brush's transformation matrix and fills a rectangle with the transformed brush.
C++
VOID Example_SetTransform(HDC hdc)
{
Graphics myGraphics(hdc);
LinearGradientBrush linGrBrush(
Rect(0, 0, 100, 50),
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255), // blue
LinearGradientModeHorizontal);
Matrix matrix(2.0, 0, 0, 1, 0, 0); // horizontal doubling
// Fill a large area with the linear gradient brush (no transformation).
myGraphics.FillRectangle(&linGrBrush, 0, 0, 800, 50);
linGrBrush.SetTransform(&matrix);
// Fill a large area with the transformed linear gradient brush.
myGraphics.FillRectangle(&linGrBrush, 0, 75, 800, 50);
}
PowerBASIC
SUB GDIP_SetLineTransform (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pLinBrush AS DWORD
LOCAL pMatrix AS DWORD
LOCAL rc AS RECTF
LOCAL colorRed AS DWORD
LOCAL colorBlue AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
rc.x = 0 : rc.y = 0 : rc.Width = 100 : rc.Height = 50
colorRed = GDIP_ARGB(255, 255, 0, 0)
colorBlue = GDIP_ARGB(255, 0, 0, 255)
hStatus = GdipCreateLineBrushFromRect(rc, colorRed, colorBlue, %LinearGradientModeHorizontal, %WrapModeTile, pLinBrush)
hStatus = GdipCreateMatrix2(2, 0, 0, 1, 0, 0, pMatrix) ' // horizontal doubling
' // Fill a large area with the linear gradient brush (no transformation).
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 800, 50)
hStatus = GdipSetLineTransform(pLinBrush, pMatrix)
' // Fill a large area with the transformed linear gradient brush.
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 75, 800, 50)
' // Cleanup
IF pMatrix THEN GdipDeleteMatrix(pMatrix)
IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetLineTransform.png)