• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipTranslateRegion

Started by José Roca, June 28, 2008, 07:29:24 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

José Roca



The following example creates a region from a path and fills it. The code then translates the region and fills the translated region to show how the region has shifted.

C++


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

   Point points[] = {
      Point(110, 20),
      Point(120, 30),
      Point(100, 60),
      Point(120, 70),
      Point(150, 60),
      Point(140, 10)};

   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);
   graphics.FillRegion(&solidBrush, &pathRegion);

   // Translate the region.
   INT dx = 100;
   INT dy = 60;
   pathRegion.Translate(dx, dy);
   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_TranslateRegion (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pSolidBrush AS DWORD
   LOCAL pPathRegion AS DWORD
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   pts(0).x = 110 : pts(0).y = 20
   pts(1).x = 120 : pts(1).y = 30
   pts(2).x = 100 : pts(2).y = 60
   pts(3).x = 120 : pts(3).y = 70
   pts(4).x = 150 : pts(4).y = 60
   pts(5).x = 140 : pts(5).y = 10

   hStatus = GdipCreatePath(%FillModeAlternate, pPath)
   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   hStatus = GdipAddPathClosedCurveI(pPath, pts(0), 6)

   ' // Create a region from a path.
   hStatus = GdipCreateRegionPath(pPath, pPathRegion)
   hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)

   ' // Translate the region.
   LOCAL dx AS LONG
   LOCAL dy AS LONG
   dx = 100
   dy = 60
   hStatus = GdipTranslateRegionI(pPathRegion, dx, dy)
   hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)

   ' // Cleanup
   IF pPathRegion THEN GdipDeleteRegion(pPathRegion)
   IF pSolidBrush THEN GdipDeleteBrush(pSolidBrush)
   IF pPath THEN GdipDeletePath(pPath)
   IF pGraphics THEN GdipDeleteGraphics(pGraphics)

END SUB


The following illustration shows the output of the preceding code.