• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipTransformPath

Started by José Roca, June 22, 2008, 06:06:16 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a GraphicsPath object and adds a rectangle to the path. The code draws the path, transforms the path, and then draws the path again.

C++


VOID TransformExample(HDC hdc)
{
   Graphics graphics(hdc);

   GraphicsPath path;
   path.AddRectangle(Rect(40, 10, 200, 50));

   // Draw the path in blue before applying a transformation.
   graphics.DrawPath(&Pen(Color(255, 0, 0, 255)), &path);

   // Transform the path.
   Matrix matrix;
   matrix.Rotate(30.0f);
   path.Transform(&matrix);

   // Draw the transformed path in red.
   graphics.DrawPath(&Pen(Color(255, 255, 0,  0)), &path);
}


PowerBASIC


SUB GDIP_TransformPath (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pBluePen AS DWORD
   LOCAL pRedPen AS DWORD
   LOCAL pMatrix AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreatePath(%FillModeAlternate, pPath)
   hStatus = GdipAddPathRectangle(pPath, 40, 10, 200, 50)

   ' // Draw the path in blue before applying a transformation.
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 255), 1, %UnitWorld, pBluePen)
   hStatus = GdipDrawPath(pGraphics, pBluePen, pPath)

   ' // Transform the path.
   hStatus = GdipCreateMatrix(pMatrix)
   hStatus = GdipRotateMatrix(pMatrix, 30, %MatrixOrderPrepend)
   hStatus = GdipTransformPath(pPath, pMatrix)
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitWorld, pRedPen)
   hStatus = GdipDrawPath(pGraphics, pRedPen, pPath)

   ' // Cleanup
   IF pBluePen THEN GdipDeletePen(pBluePen)
   IF pRedPen THEN GdipDeletePen(pRedPen)
   IF pMatrix THEN GdipDeleteMatrix(pMatrix)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB