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.
C++
VOID Example_RotateTrans(HDC hdc)
{
Graphics myGraphics(hdc);
LinearGradientBrush linGrBrush(
Rect(0, 0, 80, 40),
Color(255, 255, 0, 0), // red
Color(255, 0, 0, 255), // blue
LinearGradientModeHorizontal);
// Fill a large area with the linear gradient brush (no transformation).
myGraphics.FillRectangle(&linGrBrush, 0, 0, 800, 150);
// Apply a composite transformation: first scale, then rotate.
linGrBrush.ScaleTransform(2, 1); // horizontal doubling
linGrBrush.RotateTransform(20, MatrixOrderAppend); // 20-degree rotation
// Fill a large area with the transformed linear gradient brush.
myGraphics.FillRectangle(&linGrBrush, 0, 200, 800, 150);
}
PowerBASIC
SUB GDIP_RotateLineTransform (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
hStatus = GdipCreateFromHDC(hdc, pGraphics)
rc.x = 0 : rc.y = 0 : rc.Width = 80 : rc.Height = 40
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 using the gradient brush with the default wrap mode.
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 0, 800, 150)
' // Apply a composite transformation: first scale, then rotate.
hStatus = GdipScaleLineTransform(pLinBrush, 2, 1, %MatrixOrderPrepend) ' // horizontal doubling
hStatus = GdipRotateLineTransform(pLinBrush, 20, %MatrixOrderAppend) ' // 20-degree rotation
' // Fill a large area with the transformed linear gradient brush.
hStatus = GdipFillRectangle(pGraphics, pLinBrush, 0, 200, 800, 150)
' // Cleanup
IF pLinBrush THEN GdipDeleteBrush(pLinBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipRotateLineTransform.png)