• Welcome to Powerbasic Museum 2020-B.
 

News:

Forum in repository mode. No new members allowed.

Main Menu

GDI+: GdipSetWorldTransform

Started by José Roca, June 23, 2008, 10:44:49 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a rotation matrix and passes the address of that matrix to the GdipSetWorldTransform function. The code calls the GdipDrawRectangle function to draw a rotated rectangle.

C++


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

   // Create a rotation matrix.
   Matrix transformMatrix;
   transformMatrix.Rotate(45.0f);

   // Set the transformation matrix of the Graphics object.
   graphics.SetTransform(&transformMatrix);

   // Draw a rotated rectangle.
   Pen pen(Color(255, 0, 0, 0));
   graphics.DrawRectangle(&pen, 120, 0, 100, 50);
}


PowerBASIC


SUB GDIP_SetWorldTransform (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPen AS DWORD
   LOCAL pMatrix AS DWORD

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   ' // Create a rotation matrix.
   hStatus = GdipCreateMatrix(pMatrix)
   hStatus = GdipRotateMatrix(pMatrix, 45.0!, %MatrixOrderPrepend)

   ' // Set the transformation matrix of the Graphics object.
   hStatus = GdipSetWorldTransform(pGraphics, pMatrix)

   ' // Create a Pen
   hStatus = GdipCreatePen1(GDIP_ARGB(255,0, 0, 0), 1, %UnitPixel, pPen)

   ' // // Draw a rotated rectangle.
   hStatus = GdipDrawRectangle(pGraphics, pPen, 120, 0, 100, 50)

   ' // Cleanup
   IF pMatrix THEN GdipDeleteMatrix(pMatrix)
   IF pPen THEN GdipDeletePen(pPen)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB