• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipGetPathWorldBounds

Started by José Roca, June 22, 2008, 05:47:52 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a path that has one curve and one ellipse. The code draws the path with a thick yellow pen and a thin black pen. The GdipGetPathWorldBounds funcgtionreceives the address of the thick yellow pen and calculates a bounding rectangle for the path. Then the code draws the bounding rectangle.

C++


VOID GetBoundsExample(HDC hdc)
{
   Graphics graphics(hdc);
   Pen blackPen(Color(255, 0, 0, 0), 1);
   Pen yellowPen(Color(255, 255, 255, 0), 10);
   Pen redPen(Color(255, 255, 0, 0), 1);

   Point pts[] = {Point(120,120),
                  Point(200,130),
                  Point(150,200),
                  Point(130,180)};

   // Create a path that has one curve and one ellipse.
   GraphicsPath path;
   path.AddClosedCurve(pts, 4);
   path.AddEllipse(120, 220, 100, 40);

   // Draw the path with a thick yellow pen and a thin black pen.
   graphics.DrawPath(&yellowPen, &path);
   graphics.DrawPath(&blackPen, &path);

   // Get the path's bounding rectangle.
   RectF rect;
   path.GetBounds(&rect, NULL, &yellowPen);
   graphics.DrawRectangle(&redPen, rect); 
}

Color(255, 0, 0, 0)Color(255, 255, 0,  0)


PowerBASIC


SUB GDIP_GetPathWorldBounds (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pBlackPen AS DWORD
   LOCAL pYellowPen AS DWORD
   LOCAL pRedPen AS DWORD
   LOCAL rcf AS RECTF
   DIM   pts(3) AS POINTF

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitWorld, pBlackPen)
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 255, 0), 1, %UnitWorld, pYellowPen)
   hStatus = GdipCreatePen1(GDIP_ARGB(255, 255, 0, 0), 1, %UnitWorld, pRedPen)

   pts(0).x = 120 : pts(0).y = 120
   pts(1).x = 200 : pts(1).y = 130
   pts(2).x = 150 : pts(2).y = 200
   pts(3).x = 130 : pts(3).y = 180

   ' // Create a path that has one curve and one ellipse.
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)
   hStatus = GdipAddPathClosedCurve(pPath, pts(0), 4)
   hStatus = GdipAddPathEllipse(pPath, 120, 220, 100, 40)

   ' // Draw the path with a thick yellow pen and a thin black pen.
   hStatus = GdipDrawPath(pGraphics, pYellowPen, pPath)
   hStatus = GdipDrawPath(pGraphics, pBlackPen, pPath)
   ' // Get the path's bounding rectangle.
   hStatus = GdipGetPathWorldBounds(pPath, rcf, %NULL, pYellowPen)
   hStatus = GdipDrawRectangle(pGraphics, pRedPen, rcf.x, rcf.y, rcf.Width, rcf.Height)

   ' // Cleanup
   IF pBlackPen THEN GdipDeletePen(pBlackPen)
   IF pYellowPen THEN GdipDeletePen(pYellowPen)
   IF pRedPen THEN GdipDeletePen(pRedPen)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB