The following example calls the
GdipRotateWorldTransform function to fill its world transformation matrix with the elements that represent a 30-degree rotation. Then the code calls the
GdipMultiplyWorldTransform function to replace the world transformation matrix (which represents the 30-degree rotation) of the
Graphics object with the product of itself and a translation matrix. At that point, the world transformation matrix of the
Graphics object represents a composite transformation: first rotate, then translate. Finally, the code calls the
GdipDrawEllipse function to draw an ellipse that is rotated and translated.
C++
VOID Example_MultiplyTransform(HDC hdc
{
Graphics graphics(hdc);
Matrix matrix;
matrix.Translate(150.0f, 100.0f);
graphics.RotateTransform(30.0f); // first rotate
graphics.MultiplyTransform(&matrix, MatrixOrderAppend); // then translate
Pen pen(Color(255, 0, 0, 255));
graphics.DrawEllipse(&pen, -80, -40, 160, 80);
}
PowerBASIC
SUB GDIP_MultiplyWorldTransform (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pPen AS DWORD
LOCAL pMatrix AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
hStatus = GdipCreateMatrix(pMatrix)
hStatus = GdipTranslateMatrix(pMatrix, 150.0!, 100.0!, %MatrixOrderPrepend)
hStatus = GdipRotateWorldTransform(pGraphics, 30.0!, %MatrixOrderPrepend)
hStatus = GdipMultiplyWorldTransform(pGraphics, pMatrix, %MatrixOrderAppend)
hStatus = GdipCreatePen1(GDIP_ARGB(255,0, 0, 255), 1, %UnitPixel, pPen)
hStatus = GdipDrawEllipse(pGraphics, pPen, -80, -40, 160, 80)
' // Cleanup
IF pMatrix THEN GdipDeleteMatrix(pMatrix)
IF pPen THEN GdipDeletePen(pPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipMultiplyWorldTransform.png)