Interactive PowerBasic Forum

Legacy Software (PBWIN 9.0+/PBCC 5.0+) => Source Code => Graphics and Multimedia => GDI+ (GDI Plus) => Topic started by: José Roca on June 28, 2008, 06:38:05 PM

Title: GDI+: GdipTransformRegion
Post by: José Roca on June 28, 2008, 06:38:05 PM


The following example creates a region from a path and fills it. The code then transforms the region and fills the transformed region to show the transformation.

C++


VOID Example_Transform(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);

   // Transform the region.
   Matrix matrix(1, 0, 0, 3, 100, 0);  // vertical stretch, shift right
   pathRegion.Transform(&matrix);
   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_TransformRegion (BYVAL hdc AS DWORD)

   LOCAL hStatus AS LONG
   LOCAL pGraphics AS DWORD
   LOCAL pPath AS DWORD
   LOCAL pSolidBrush AS DWORD
   LOCAL pPathRegion AS DWORD
   LOCAL pMatrix 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)

   ' // Transform the region.
   hStatus = GdipCreateMatrix2(1, 0, 0, 3, 100, 0, pMatrix)   ' // vertical stretch, shift right
   hStatus = GdipTransformRegion(pPathRegion, pMatrix)
   hStatus = GdipFillRegion(pGraphics, pSolidBrush, pPathRegion)

   ' // Cleanup
   IF pMatrix THEN GdipDeleteMatrix(pMatrix)
   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.

(http://www.jose.it-berater.org/captures/GdipTransformRegion.png)