• Welcome to Jose's Read Only Forum 2023.
 

GDI+: GdipCombineRegionRect

Started by José Roca, June 25, 2008, 02:35:30 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 then uses a rectangle to update the region. The updated region is the union of the path region and a rectangle.

C++


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

   Rect rect(65, 15, 70, 45);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Form the union of the region and a rectangle.
   pathRegion.Union(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectI (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 rc AS RECTL
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   SetRect rc, 65, 15, 70, 45
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Form the union of the region and a rectangle.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeUnion)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

#1
 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   Rect rect(65, 15, 70, 45);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Perform an exclusive OR operation on the region and a rectangle.
   pathRegion.Xor(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectI (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 rc AS RECTL
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   SetRect rc, 65, 15, 70, 45
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Perform an exclusive OR operation on the region and a rectangle.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeXor)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

#2
 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

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

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

   Rect rect(65, 15, 70, 45);

   GraphicsPath path;

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region region(&path);

   // Update the region so that it consists of all points inside the
   // rectangle but outside the path region.
   region.Complement(rect);

   graphics.FillRegion(&solidBrush, &region);
}


PowerBASIC


SUB GDIP_CombineRegionRectI (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 rc AS RECTL
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   SetRect rc, 65, 15, 70, 45
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Update the region so that it consists of all points inside the
   ' // rectangle but outside the path region.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeComplement)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca



The following example creates a region from a path and then uses a rectangle to update the region. The updated region is the union of the path region and a rectangle.

C++


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

   RectF rect(65.3f, 15.1f, 70.0f, 45.8f);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Form the union of the region and a rectangle.
   pathRegion.Union(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectI (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 rc AS RECTF
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   rc.x = 65.3! : rc.y = 15.1! : rc.Width = 70.0! : rc.Height = 45.8!
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Form the union of the region and a rectangle.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeUnion)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

#4
 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   RectF rect(65.3f, 15.1f, 70.0f, 45.8f);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Form the union of the region and a rectangle.
   pathRegion.Xor(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectF (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 rc AS RECTF
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   rc.x = 65.3! : rc.y = 15.1! : rc.Width = 70.0! : rc.Height = 45.8!
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Form the union of the region and a rectangle.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeXor)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

#5
 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   RectF rect(65.3f, 15.1f, 70.0f, 45.8f);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Form the union of the region and a rectangle.
   pathRegion.Complement(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectF (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 rc AS RECTF
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   rc.x = 65.3! : rc.y = 15.1! : rc.Width = 70.0! : rc.Height = 45.8!
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Form the union of the region and a rectangle.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeComplement)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   Rect rect(65, 15, 70, 45);

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

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Exclude a rectangle from the path region.
   pathRegion.Exclude(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectI (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 rc AS RECTL
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   SetRect rc, 65, 15, 70, 45
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Exclude a rectangle from the path region.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeExclude)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   RectF rect(65.3f, 15.1f, 70.0f, 45.8f);

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

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);

   // Exclude a rectangle from the path region.
   pathRegion.Exclude(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectF (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 rc AS RECTF
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   rc.x = 65.3! : rc.y = 15.1! : rc.Width = 70.0! : rc.Height = 45.8!
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Exclude the intersecting portion of the path interior from the region.
   hStatus = GdipCombineRegionRect(pPathRegion, rc, %CombineModeExclude)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   RectF rect(65.2f, 15.0f, 70.9f, 45.0f);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
   Region pathRegion(&path);   

   // Update the region to the portion that intersects with the rectangle.
   pathRegion.Intersect(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectF (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 rc AS RECTF
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   rc.x = 65.3! : rc.y = 15.1! : rc.Width = 70.0! : rc.Height = 45.8!
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Exclude the intersecting portion of the path interior from the region.
   hStatus = GdipCombineRegionRect(pPathRegion, rc, %CombineModeIntersect)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.



José Roca

 
The following example creates a region from a path and then uses a rectangle to update the region.

C++


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

   Rect rect(65, 15, 70, 45);
   GraphicsPath path;
   SolidBrush solidBrush(Color(255, 255, 0, 0));

   path.AddClosedCurve(points, 6);

   // Create a region from a path.
    Region pathRegion(&path);   
   
   // Update the region to the portion that intersects with the rectangle.
   pathRegion.Intersect(rect);

   graphics.FillRegion(&solidBrush, &pathRegion);
}


PowerBASIC


SUB GDIP_CombineRegionRectI (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 rc AS RECTL
   DIM   pts(5) AS POINTL

   hStatus = GdipCreateFromHDC(hdc, pGraphics)

   hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 255, 0, 0), pSolidBrush)

   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

   SetRect rc, 65, 15, 70, 45
   hStatus = GdipCreatePath(%FillModeAlternate, pPath)

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

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

   ' // Exclude a rectangle from the path region.
   hStatus = GdipCombineRegionRectI(pPathRegion, rc, %CombineModeIntersect)

   ' // Fill the union of the two regions with a semitransparent blue brush.
   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.