The following example sets the world transformation of a
Graphics object to a 45-degree rotation and then draws a rectangle. The code calls the
GdipResetWorldTransform method of the
Graphics object and then draws a second rectangle. No rotation transformation is applied to the second rectangle.
C++
VOID Example_ResetTransform(HDC hdc)
{
Graphics graphics(hdc);
// Rotate the transformation and draw a rectangle.
graphics.RotateTransform(45.0f);
Pen blackPen(Color(255, 0, 0, 0));
graphics.DrawRectangle(&blackPen, 100, 0, 100, 50);
// Reset the transformation to identity, and draw a second rectangle.
graphics.ResetTransform();
Pen redPen(Color(255, 255, 0, 0));
graphics.DrawRectangle(&redPen, 110, 0, 100, 50);
}
PowerBASIC
SUB GDIP_ResetWorldTransform (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pBlackPen AS DWORD
LOCAL pRedPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Rotate the transformation and draw a rectangle.
hStatus = GdipRotateWorldTransform(pGraphics, 45.0!, %MatrixOrderPrepend)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitPixel, pBlackPen)
hStatus = GdipDrawRectangle(pGraphics, pBlackPen, 100, 0, 100, 50)
' // Reset the transformation to identity, and draw a second rectangle.
hStatus = GdipResetWorldTransform(pGraphics)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitPixel, pRedPen)
hStatus = GdipDrawRectangle(pGraphics, pRedPen, 100, 0, 100, 50)
' // Cleanup
IF pRedPen THEN GdipDeletePen(pRedPen)
IF pBlackPen THEN GdipDeletePen(pBlackPen)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipResetWorldTransform.png)